ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zq_class.cpp
Date: 2025-11-13 04:25:43
Exec Total Coverage
Lines: 3109 8718 35.7%
Functions: 84 304 27.6%
Branches: 2695 7701 35.0%

Line Branch Exec Source
1 #include <chrono>
2 #include <cstring>
3 #include <exception>
4 #include <string>
5 #include <stdexcept>
6 #include <map>
7
8 #include "base/general.h"
9 #include "base/version.h"
10 #include "base/zapp.h"
11 #include "base/zdefs.h"
12 #include "dialog/info.h"
13 #include "metadata/metadata.h"
14
15 #include "base/qrs.h"
16 #include "base/dmap.h"
17 #include "base/packfile.h"
18 #include "base/cpool.h"
19 #include "base/autocombo.h"
20 #include "base/gui.h"
21 #include "base/msgstr.h"
22 #include "zc/zelda.h"
23 #include "zq/zq_class.h"
24 #include "zq/zq_misc.h"
25 #include "zq/zquest.h"
26 #include "base/qst.h"
27 #include "base/colors.h"
28 #include "tiles.h"
29 #include "base/zsys.h"
30 #include "sprite.h"
31 #include "items.h"
32 #include "zc/zc_sys.h"
33 #include "base/md5.h"
34 #include "hero_tiles.h"
35 #include "subscr.h"
36 #include "zq/zq_strings.h"
37 #include "zq/zq_subscr.h"
38 #include "zc/ffscript.h"
39 #include "base/util.h"
40 #include "zq/zq_files.h"
41 #include "dialog/alert.h"
42 #include "slopes.h"
43 #include "drawing.h"
44 #include "zinfo.h"
45 #include "zq/render_minimap.h"
46 #include "base/mapscr.h"
47 #include "iter.h"
48 #include <fmt/format.h>
49 #include <filesystem>
50
51 #ifdef __EMSCRIPTEN__
52 #include "base/emscripten_utils.h"
53 #endif
54
55 namespace fs = std::filesystem;
56
57 using namespace util;
58
59 extern uint8_t ViewLayer3BG, ViewLayer2BG;
60 extern int32_t LayerDitherBG, LayerDitherSz;
61 extern bool NoHighlightLayer0;
62
63 using std::string;
64 using std::pair;
65
66 #define COLOR_SOLID vc(4)
67 #define COLOR_SLOPE vc(13)
68 #define COLOR_LADDER vc(6)
69 //#define COLOR_EFFECT vc(10)
70
71 //const char zqsheader[30]="ZQuest Classic String Table\n\x01";
72 extern char msgbuf[MSG_NEW_SIZE*8];
73
74 extern string zScript;
75
76 12 zmap Map;
77 int32_t prv_mode=0;
78
79 bool save_warn=true;
80
81 int32_t COMBOPOS(int32_t x, int32_t y)
82 {
83 return (((y) & 0xF0) + ((x) >> 4));
84 }
85 int32_t COMBOPOS_B(int32_t x, int32_t y)
86 {
87 if(unsigned(x) >= 256 || unsigned(y) >= 176)
88 return -1;
89 return COMBOPOS(x,y);
90 }
91 int32_t COMBOX(int32_t pos)
92 {
93 return ((pos) % 16 * 16);
94 }
95 int32_t COMBOY(int32_t pos)
96 {
97 return ((pos) & 0xF0);
98 }
99
100 void reset_dmap(int32_t index)
101 {
102 bound(index,0,MAXDMAPS-1);
103 DMaps[index].clear();
104 DMaps[index].title = "";
105 sprintf(DMaps[index].intro, " ");
106 }
107
108 void reset_dmaps()
109 {
110 for(int32_t i=0; i<MAXDMAPS; i++)
111 reset_dmap(i);
112 }
113
114 void truncate_dmap_title(std::string& title)
115 {
116 title.resize(21, ' ');
117 }
118
119 mapscr* zmap::get_prvscr()
120 {
121 return &prvscr;
122 }
123
124
7/12
✓ Branch 0 taken 23 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 138 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 115 times.
✓ Branch 7 taken 23 times.
✓ Branch 8 taken 23 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 23 times.
138 zmap::zmap()
125 {
126 23 can_paste=false;
127 23 prv_cmbcycle=0;
128 23 prv_advance=0;
129 23 prv_freeze=0;
130 23 copyffc=-1;
131
132 23 memset(scrpos, 0, sizeof(scrpos));
133 23 memset(scrview, 0, sizeof(scrview));
134 23 screens=NULL;
135 23 prv_time=0;
136 23 prv_scr=0;
137 23 prv_map=0;
138 23 copyscr=0;
139 23 cursor={};
140 copymap=0;
141 layer_target_map = 0;
142 layer_target_scr = 0;
143 layer_target_multiple = 0;
144 }
145
146 11 void zmap::clear()
147 {
148
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 *this = zmap();
149 11 }
150 void zmap::force_refr_pointer()
151 {
152 if(unsigned(cursor.map) > map_count || (cursor.map*MAPSCRS > TheMaps.size()))
153 screens = nullptr;
154 else screens = &TheMaps[cursor.map*MAPSCRS];
155 }
156 bool zmap::CanUndo()
157 {
158 return undo_stack.size() > 0;
159 }
160 bool zmap::CanRedo()
161 {
162 return redo_stack.size() > 0;
163 }
164 bool zmap::CanPaste()
165 {
166 return can_paste;
167 }
168 int32_t zmap::CopyScr()
169 {
170 return (copymap<<8)+copyscr;
171 }
172 int32_t zmap::getCopyFFC()
173 {
174 return copyffc;
175 }
176 set_ffc_command::data_t zmap::getCopyFFCData()
177 {
178 return set_ffc_command::create_data(copymapscr.ffcs[copyffc]);
179 }
180 46 int32_t zmap::getMapCount()
181 {
182 46 return map_count;
183 }
184 int32_t zmap::getLayerTargetMap()
185 {
186 return layer_target_map;
187 }
188 int32_t zmap::getLayerTargetScr()
189 {
190 return layer_target_scr;
191 }
192 int32_t zmap::getLayerTargetMultiple()
193 {
194 return layer_target_multiple;
195 }
196 bool zmap::isDungeon(int32_t scr)
197 {
198 for(int32_t i=0; i<4; i++)
199 {
200 if(screens[scr].data[i]!=screens[TEMPLATE].data[i])
201 {
202 return false;
203 }
204 }
205
206 return true;
207 }
208
209 bool zmap::clearall(bool validate)
210 {
211 Color=0;
212 char tbuf[10];
213
214 if((header.templatepath[0]!=0)&&validate)
215 {
216 if(!valid_zqt(header.templatepath))
217 {
218 jwin_alert("Error","Invalid Quest Template",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
219 return false;
220 }
221 }
222
223 for(int32_t i=0; i<map_count; i++)
224 {
225 setCurrMap(i);
226 sprintf(tbuf, "%d", i);
227 clearmap(true);
228 }
229
230 setCurrMap(0);
231 return true;
232 }
233
234 bool zmap::reset_templates(bool validate)
235 {
236 //why are we doing this?
237 if(colordata==NULL)
238 {
239 return false;
240 }
241
242 //int32_t ret;
243 word version, build, dummy, sversion=0;
244 byte dummyc;
245 word dummyw;
246 //int32_t section_size;
247 word temp_map_count;
248 mapscr temp_mapscr;
249 PACKFILE *f=NULL;
250
251 // setPackfilePassword(datapwd);
252 f=open_quest_template(&header, "modules/classic/default.qst", validate);
253 get_version_and_build(f, &version, &build);
254
255 if(!find_section(f, ID_MAPS))
256 {
257 // setPackfilePassword(NULL);
258 return false;
259 }
260
261 //section version info
262 if(!p_igetw(&sversion,f))
263 {
264 return false;
265 }
266
267 if(!p_igetw(&dummy,f))
268 {
269 return false;
270 }
271
272 //section size
273 dword dummy_size;
274 if(!p_igetl(&dummy_size,f))
275 {
276 return false;
277 }
278
279 //finally... section data
280 if(!p_igetw(&temp_map_count,f))
281 {
282 return false;
283 }
284
285 if(version>12)
286 {
287 if(!p_getc(&dummyc,f))
288 return qe_invalid;
289
290 if(!p_getc(&dummyc,f))
291 return qe_invalid;
292
293 if(!p_igetw(&dummyw,f))
294 return qe_invalid;
295
296 if(!p_igetw(&dummyw,f))
297 return qe_invalid;
298
299 if(!p_igetw(&dummyw,f))
300 return qe_invalid;
301
302 if(!p_igetw(&dummyw,f))
303 return qe_invalid;
304
305 if(!p_igetw(&dummyw,f))
306 return qe_invalid;
307
308 if(!p_igetw(&dummyw,f))
309 return qe_invalid;
310
311 if(!p_igetw(&dummyw,f))
312 return qe_invalid;
313
314 if(!p_igetw(&dummyw,f))
315 return qe_invalid;
316
317 if(!p_igetw(&dummyw,f))
318 return qe_invalid;
319
320 if(!p_igetw(&dummyw,f))
321 return qe_invalid;
322
323 if(!p_getc(&dummyc,f))
324 return qe_invalid;
325
326 if(!p_getc(&dummyc,f))
327 return qe_invalid;
328 }
329
330 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
331 {
332 readmapscreen(f, &header, &temp_mapscr, sversion);
333 }
334
335 readmapscreen(f, &header, &TheMaps[128], sversion);
336 readmapscreen(f, &header, &TheMaps[129], sversion);
337
338 for(int32_t i=0; i<(MAPSCRS-(MAPSCRSNORMAL+2)); ++i)
339 {
340 readmapscreen(f, &header, &temp_mapscr, sversion);
341 }
342
343 if(version>12)
344 {
345 if(!p_getc(&dummyc,f))
346 return qe_invalid;
347
348 if(!p_getc(&dummyc,f))
349 return qe_invalid;
350
351 if(!p_igetw(&dummyw,f))
352 return qe_invalid;
353
354 if(!p_igetw(&dummyw,f))
355 return qe_invalid;
356
357 if(!p_igetw(&dummyw,f))
358 return qe_invalid;
359
360 if(!p_igetw(&dummyw,f))
361 return qe_invalid;
362
363 if(!p_igetw(&dummyw,f))
364 return qe_invalid;
365
366 if(!p_igetw(&dummyw,f))
367 return qe_invalid;
368
369 if(!p_igetw(&dummyw,f))
370 return qe_invalid;
371
372 if(!p_igetw(&dummyw,f))
373 return qe_invalid;
374
375 if(!p_igetw(&dummyw,f))
376 return qe_invalid;
377
378 if(!p_igetw(&dummyw,f))
379 return qe_invalid;
380
381 if(!p_getc(&dummyc,f))
382 return qe_invalid;
383
384 if(!p_getc(&dummyc,f))
385 return qe_invalid;
386 }
387
388 for(int32_t i=0; i<MAPSCRSNORMAL; ++i)
389 {
390 readmapscreen(f, &header, &temp_mapscr, sversion);
391 }
392
393 readmapscreen(f, &header, &TheMaps[MAPSCRS+128], sversion);
394 readmapscreen(f, &header, &TheMaps[MAPSCRS+129], sversion);
395
396 pack_fclose(f);
397 clear_quest_tmpfile();
398
399 return true;
400 }
401
402 bool zmap::clearmap(bool newquest)
403 {
404 if(cursor.map<map_count)
405 {
406 for(int32_t i=0; i<MAPSCRS-(newquest?0:TEMPLATES); i++)
407 {
408 clearscr(i);
409 }
410
411 setCurrScr(0);
412
413 if(newquest)
414 {
415 if(!reset_templates(false))
416 {
417 jwin_alert("Error","Error resetting","template screens.",NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
418 }
419 }
420 }
421
422 return true;
423 }
424
425 MapCursor zmap::getCursor() const
426 {
427 return cursor;
428 }
429
430 void zmap::setCursor(MapCursor new_cursor)
431 {
432 if (cursor == new_cursor)
433 return;
434
435 if (!screens) Color = -1;
436
437 cursor = new_cursor;
438
439 refresh_color();
440
441 reset_combo_animations2();
442 mmap_mark_dirty();
443 regions_mark_dirty();
444 refresh(rALL);
445 }
446
447 bool zmap::isValidPosition(ComboPosition pos) const
448 {
449 return pos.is_valid(cursor);
450 }
451
452 int zmap::getScreenForPosition(ComboPosition pos) const
453 {
454 return cursor.viewscr + pos.screen_offset();
455 }
456
457 mapscr* zmap::CurrScr()
458 {
459 return screens+cursor.screen;
460 }
461 mapscr* zmap::Scr(int32_t scr)
462 {
463 return screens+scr;
464 }
465 mapscr* zmap::Scr(ComboPosition pos)
466 {
467 if (!pos.is_valid(cursor))
468 return nullptr;
469
470 int screen_offset = pos.screen_offset();
471 int screen = cursor.viewscr + screen_offset;
472 return AbsoluteScr(cursor.map, screen);
473 }
474 mapscr* zmap::Scr(ComboPosition pos, int layer)
475 {
476 int map = cursor.map;
477 int screen = cursor.viewscr + pos.screen_offset();
478 if (layer)
479 {
480 mapscr* scr = Map.AbsoluteScr(map, screen);
481 map = scr->layermap[CurrentLayer-1]-1;
482 screen = scr->layerscreen[CurrentLayer-1];
483 }
484
485 return AbsoluteScr(map, screen);
486 }
487 mapscr* zmap::ScrMakeValid(ComboPosition pos, int layer)
488 {
489 mapscr* scr = Scr(pos, layer);
490 if (scr && !(scr->valid&mVALID))
491 {
492 scr->valid |= mVALID;
493 setcolor(Color, scr);
494 }
495 return scr;
496 }
497 mapscr* zmap::AbsoluteScr(int32_t scr)
498 {
499 if(unsigned(scr) >= MAPSCRS*getMapCount())
500 return nullptr;
501 return &TheMaps[scr];
502 }
503 mapscr* zmap::AbsoluteScr(int32_t map, int32_t scr)
504 {
505 if(map < 0 || map >= getMapCount() || scr < 0 || scr >= MAPSCRS)
506 return nullptr;
507 return AbsoluteScr((map*MAPSCRS)+scr);
508 }
509 mapscr* zmap::AbsoluteScrMakeValid(int32_t map, int32_t screen)
510 {
511 mapscr* scr = AbsoluteScr(map, screen);
512 if (scr && !(scr->valid&mVALID))
513 {
514 scr->valid |= mVALID;
515 setcolor(Color, scr);
516 }
517 return scr;
518 }
519 void zmap::set_prvscr(int32_t map, int32_t scr)
520 {
521 prvscr = *get_canonical_scr(map, scr);
522
523 for(int32_t i=0; i<6; i++)
524 {
525 if(prvscr.layermap[i]>0)
526 {
527 prvlayers[i] = *get_canonical_scr(prvscr.layermap[i] - 1, prvscr.layerscreen[i]);
528 }
529 else
530 prvlayers[i].valid = 0;
531 }
532
533 prv_map=map;
534 prv_scr=scr;
535 }
536 92 int32_t zmap::getCurrMap()
537 {
538 92 return cursor.map;
539 }
540 21 void zmap::regions_mark_dirty()
541 {
542 21 regions_dirty = true;
543 21 }
544 void zmap::regions_refresh()
545 {
546 if (!regions_dirty)
547 return;
548
549 regions_dirty = false;
550 region_descriptions.clear();
551
552 current_map_region_ids = Regions[cursor.map].get_all_region_ids();
553 if (!get_all_region_descriptions(region_descriptions, current_map_region_ids))
554 region_descriptions.clear();
555 }
556 const std::vector<region_description>& zmap::get_region_descriptions()
557 {
558 regions_refresh();
559 return region_descriptions;
560 }
561 bool zmap::is_region(int screen)
562 {
563 if (screen < 0 || screen >= 128)
564 return false;
565
566 regions_refresh();
567 return current_map_region_ids[screen];
568 }
569 bool zmap::isDark(int scr)
570 {
571 return (screens[scr].flags&fDARK)!=0;
572 }
573 bool zmap::isValid(int32_t scr)
574 {
575 return (screens[scr].valid&mVALID)!=0;
576 }
577 bool zmap::isValid(int32_t map, int32_t scr)
578 {
579 return (AbsoluteScr(map, scr)->valid&mVALID)!=0;
580 }
581
582 11 void zmap::setCurrMap(int32_t index)
583 {
584
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!screens) Color = -1;
585 11 scrpos[cursor.map] = cursor.screen;
586 11 scrview[cursor.map] = cursor.viewscr;
587 11 cursor.map = bound(index,0,map_count);
588 11 screens = &TheMaps[cursor.map*MAPSCRS];
589
590 11 cursor.viewscr = scrview[cursor.map];
591 11 cursor.setScreen(scrpos[cursor.map]);
592
593 11 refresh_color();
594
595 11 reset_combo_animations2();
596 11 mmap_mark_dirty();
597 11 regions_mark_dirty();
598 11 }
599
600 20 int32_t zmap::getCurrScr()
601 {
602 20 return cursor.screen;
603 }
604 11 void zmap::setCurrScr(int32_t scr)
605 {
606
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
11 if (scr == cursor.screen)
607 1 return;
608
609 10 cursor.setScreen(scr);
610
611 10 refresh_color();
612
613 10 reset_combo_animations2();
614 10 setlayertarget();
615 10 mmap_mark_dirty();
616 10 regions_mark_dirty();
617 11 }
618
619 int32_t zmap::getViewScr()
620 {
621 return cursor.viewscr;
622 }
623
624 11 void zmap::setViewSize(int32_t size)
625 {
626 11 cursor.setSize(size);
627 11 }
628
629 8 int32_t zmap::getViewSize()
630 {
631 8 return cursor.size;
632 }
633
634 10 void zmap::setlayertarget()
635 {
636 10 layer_target_map = 0;
637 10 layer_target_multiple = 0;
638
639
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 10 times.
46 for(int32_t m=0; m<getMapCount(); ++m)
640 {
641
2/2
✓ Branch 0 taken 4896 times.
✓ Branch 1 taken 36 times.
4932 for(int32_t s=0; s<MAPSCRS; ++s)
642 {
643 4896 int32_t i=(m*MAPSCRS+s);
644 4896 mapscr *ts=&TheMaps[i];
645
646 // Search through each layer
647
2/2
✓ Branch 0 taken 29376 times.
✓ Branch 1 taken 4896 times.
34272 for(int32_t w=0; w<6; ++w)
648 {
649
3/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 29365 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
29376 if(ts->layerscreen[w]==cursor.screen && (ts->layermap[w]-1)==cursor.map)
650 {
651 if(layer_target_map > 0)
652 {
653 layer_target_multiple += 1;
654 continue;
655 }
656
657 layer_target_map = m+1;
658 layer_target_scr = s;
659 }
660 29376 }
661 4896 }
662 36 }
663 10 }
664
665 21 void zmap::refresh_color()
666 {
667 21 auto color = getcolor();
668
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 if (Color != color)
669 {
670 21 loadlvlpal(color);
671 21 rebuild_trans_table();
672 21 }
673 21 }
674
675 void zmap::setcolor(int color, mapscr* scr)
676 {
677 if (!scr)
678 scr = CurrScr();
679 scr->valid |= mVALID;
680 scr->color = color;
681
682 refresh_color();
683
684 mmap_mark_dirty();
685 }
686
687 21 int32_t zmap::getcolor()
688 {
689
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 mapscr& scr = prv_mode ? prvscr : screens[cursor.screen];
690
691
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
21 if (scr.valid & mVALID)
692 18 return scr.color;
693
694 3 return map_infos[cursor.map].autopalette;
695 21 }
696
697 void zmap::resetflags()
698 {
699 byte *di=&(screens[cursor.screen].valid);
700
701 for(int32_t i=1; i<48; i++)
702 {
703 *(di+i)=0;
704 }
705 }
706
707 word zmap::tcmbdat(int32_t pos)
708 {
709 return screens[TEMPLATE].data[pos];
710 }
711
712 word zmap::tcmbcset(int32_t pos)
713 {
714 return screens[TEMPLATE].cset[pos];
715 }
716
717 int32_t zmap::tcmbflag(int32_t pos)
718 {
719 return screens[TEMPLATE].sflag[pos];
720 }
721
722 word zmap::tcmbdat2(int32_t pos)
723 {
724 return screens[TEMPLATE2].data[pos];
725 }
726
727 word zmap::tcmbcset2(int32_t pos)
728 {
729 return screens[TEMPLATE2].cset[pos];
730 }
731
732 int32_t zmap::tcmbflag2(int32_t pos)
733 {
734 return screens[TEMPLATE2].sflag[pos];
735 }
736
737 void zmap::TemplateAll()
738 {
739 StartListCommand();
740 for(int32_t i=0; i<128; i++)
741 {
742 if((screens[i].valid&mVALID) && isDungeon(i))
743 DoTemplateCommand(-1, -1, i);
744 }
745 FinishListCommand();
746 }
747
748 void zmap::Template(int32_t floorcombo, int32_t floorcset, int32_t scr)
749 {
750 if(scr==TEMPLATE)
751 return;
752
753 if(!(screens[scr].valid&mVALID))
754 screens[scr].color=Color;
755
756 screens[scr].valid|=mVALID;
757
758 for(int32_t i=0; i<32; i++)
759 {
760 screens[scr].data[i]=screens[TEMPLATE].data[i];
761 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
762 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
763 }
764
765 for(int32_t i=144; i<176; i++)
766 {
767 screens[scr].data[i]=screens[TEMPLATE].data[i];
768 screens[scr].cset[i]=screens[TEMPLATE].cset[i];
769 screens[scr].sflag[i]=screens[TEMPLATE].sflag[i];
770 }
771
772 for(int32_t y=2; y<=9; y++)
773 {
774 int32_t j=y<<4;
775 screens[scr].data[j]=screens[TEMPLATE].data[j];
776 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
777 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
778 ++j;
779 screens[scr].data[j]=screens[TEMPLATE].data[j];
780 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
781 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
782 ++j;
783 j+=12;
784 screens[scr].data[j]=screens[TEMPLATE].data[j];
785 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
786 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
787 ++j;
788 screens[scr].data[j]=screens[TEMPLATE].data[j];
789 screens[scr].cset[j]=screens[TEMPLATE].cset[j];
790
791 screens[scr].sflag[j]=screens[TEMPLATE].sflag[j];
792 ++j;
793 }
794
795 if(floorcombo!=-1)
796 {
797 for(int32_t y=2; y<9; y++)
798 for(int32_t x=2; x<14; x++)
799 {
800 int32_t i=(y<<4)+x;
801 screens[scr].data[i] = floorcombo;
802 screens[scr].cset[i] = floorcset;
803 }
804 }
805
806 for(int32_t i=0; i<4; i++)
807 putdoor(scr,i,screens[scr].door[i]);
808 }
809
810
811 void zmap::clearscr(int32_t scr)
812 {
813 screens[scr].zero_memory();
814 screens[scr].valid=mVERSION;
815 auto const& mapinf = map_infos[cursor.map];
816 for(int q = 0; q < 6; ++q)
817 {
818 auto layer = mapinf.autolayers[q];
819 screens[scr].layermap[q] = layer;
820 screens[scr].layerscreen[q] = layer ? scr : 0;
821 }
822 screens[scr].color = mapinf.autopalette;
823 if (scr == cursor.screen)
824 refresh_color();
825 mmap_mark_dirty();
826 }
827
828 const char *loaderror[] =
829 {
830
831 "OK","File not found","Incomplete data",
832 "Invalid version","Invalid file"
833
834 };
835
836 int32_t zmap::load(const char *path)
837 {
838 PACKFILE *f=pack_fopen_password(path,F_READ, "");
839
840 if(!f)
841 return 1;
842
843
844 int16_t version;
845 byte build;
846
847 //get the version
848 if(!p_igetw(&version,f))
849 {
850 goto file_error;
851 }
852
853 //get the build
854 if(!p_getc(&build,f))
855 {
856 goto file_error;
857 }
858
859 for(int32_t i=0; i<MAPSCRS; i++)
860 {
861 mapscr tmpimportscr;
862 tmpimportscr.zero_memory();
863 if(readmapscreen(f,&header,&tmpimportscr,version)==qe_invalid)
864 {
865 al_trace("failed zmap::load\n");
866 goto file_error;
867 }
868
869 switch(ImportMapBias)
870 {
871 case 0:
872 *(screens+i) = tmpimportscr;
873 break;
874
875 case 1:
876 if(!(screens[i].valid&mVALID))
877 {
878 *(screens+i) = tmpimportscr;
879 }
880 break;
881
882 case 2:
883 if(tmpimportscr.valid&mVALID)
884 {
885 *(screens+i) = tmpimportscr;
886 }
887 break;
888 }
889 }
890
891
892 pack_fclose(f);
893
894 setCurrScr(0);
895 mmap_mark_dirty();
896 regions_mark_dirty();
897 return 0;
898
899 file_error:
900 pack_fclose(f);
901 clearmap(false);
902 return 2;
903 }
904
905 int32_t zmap::save(const char *path)
906 {
907 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
908
909 if(!f)
910 return 1;
911
912 if(!p_iputw(V_MAPS,f))
913 {
914 pack_fclose(f);
915 return 3;
916 }
917
918 // This was the "build number", but that's totally useless here. Keep this junk byte
919 // so as not to totally break exports between ZC versions.
920 if(!p_putc(0,f))
921 {
922 pack_fclose(f);
923 return 3;
924 }
925
926 for(int32_t i=0; i<MAPSCRS; i++)
927 {
928 if(writemapscreen(f,this->getCurrMap(),i) == qe_invalid)
929 {
930 pack_fclose(f);
931 return 2;
932 }
933 }
934
935 pack_fclose(f);
936 return 0;
937 }
938
939
940 bool zmap::ishookshottable(int32_t bx, int32_t by, int32_t i)
941 {
942 // Hookshots can be blocked by solid combos on all 3 ground layers.
943 const newcombo* c = &combobuf[MAPCOMBO(bx,by)];
944
945 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
946 return true;
947 if (c->walk&(1<<i))
948 return false;
949
950 for(int32_t k=0; k<2; k++)
951 {
952 c = &combobuf[MAPCOMBO2(k+1,bx,by)];
953
954 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
955 {
956 return false;
957 }
958 }
959
960 return true;
961 }
962
963 bool zmap::ishookshottable(int32_t map, int32_t screen, int32_t bx, int32_t by, int32_t i)
964 {
965 // Hookshots can be blocked by solid combos on all 3 ground layers.
966 const newcombo* c = &combobuf[MAPCOMBO3(map, screen, -1, bx,by)];
967
968 if(c->type == cHOOKSHOTONLY || c->type == cLADDERHOOKSHOT)
969 return true;
970 if (c->walk&(1<<i))
971 return false;
972
973 for(int32_t k=0; k<2; k++)
974 {
975 c = &combobuf[MAPCOMBO3(map, screen, k+1,bx,by)];
976
977 if(c->type != cHOOKSHOTONLY && c->type != cLADDERHOOKSHOT && c->walk&(1<<i))
978 {
979 return false;
980 }
981 }
982
983 return true;
984 }
985
986 bool zmap::isstepable(int32_t combo)
987 {
988 // This is kind of odd but it's true to the engine (see maps.cpp)
989 return (combo_class_buf[combobuf[combo].type].ladder_pass);
990 }
991
992 // Returns the letter of the warp combo.
993 int32_t zmap::warpindex(int32_t combo)
994 {
995 switch(combobuf[combo].type)
996 {
997 case cCAVE:
998 case cPIT:
999 case cSTAIR:
1000 case cCAVE2:
1001 case cSWIMWARP:
1002 case cDIVEWARP:
1003 case cSWARPA:
1004 return 0;
1005
1006 case cCAVEB:
1007 case cPITB:
1008 case cSTAIRB:
1009 case cCAVE2B:
1010 case cSWIMWARPB:
1011 case cDIVEWARPB:
1012 case cSWARPB:
1013 return 1;
1014
1015 case cCAVEC:
1016 case cPITC:
1017 case cSTAIRC:
1018 case cCAVE2C:
1019 case cSWIMWARPC:
1020 case cDIVEWARPC:
1021 case cSWARPC:
1022 return 2;
1023
1024 case cCAVED:
1025 case cPITD:
1026 case cSTAIRD:
1027 case cCAVE2D:
1028 case cSWIMWARPD:
1029 case cDIVEWARPD:
1030 case cSWARPD:
1031 return 3;
1032
1033 case cPITR:
1034 case cSTAIRR:
1035 case cSWARPR:
1036 return 4;
1037 }
1038
1039 return -1;
1040
1041 }
1042
1043 void draw_ladder(BITMAP* dest, int32_t x, int32_t y, int32_t c, bool top = false)
1044 {
1045 if(top)
1046 line(dest,x,y,x+15,y,c);
1047 rectfill(dest,x,y,x+3,y+15,c);
1048 rectfill(dest,x+12,y,x+15,y+15,c);
1049 rectfill(dest,x+4,y+2,x+11,y+5,c);
1050 rectfill(dest,x+4,y+10,x+11,y+13,c);
1051 }
1052
1053 void draw_platform(BITMAP* dest, int32_t x, int32_t y, int32_t c)
1054 {
1055 line(dest,x,y,x+15,y,c);
1056 }
1057
1058 void zmap::put_walkflags_layered(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer)
1059 {
1060 int32_t cx = COMBOX(pos);
1061 int32_t cy = COMBOY(pos);
1062
1063 newcombo const& c = combobuf[ MAPCOMBO2(layer,cx,cy) ];
1064
1065 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1066
1067 int32_t bridgedetected = 0;
1068
1069 for(int32_t i=0; i<4; i++)
1070 {
1071 int32_t tx=((i&2)<<2)+x;
1072 int32_t ty=((i&1)<<3)+y;
1073 int32_t tx2=((i&2)<<2)+cx;
1074 int32_t ty2=((i&1)<<3)+cy;
1075 for (int32_t m = layer; m <= 1; m++)
1076 {
1077 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1078 {
1079 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1080 {
1081 bridgedetected |= (1<<i);
1082 }
1083 }
1084 else
1085 {
1086 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1087 {
1088 bridgedetected |= (1<<i);
1089 }
1090 }
1091 }
1092 if (bridgedetected & (1<<i))
1093 {
1094 if (i >= 3) break;
1095 else continue;
1096 }
1097 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1098 {
1099 for(int32_t k=0; k<8; k+=2)
1100 for(int32_t j=0; j<8; j+=2)
1101 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1102 }
1103 if (!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1104 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1105
1106 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1107 {
1108 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO(cx,cy)) && ishookshottable(cx,cy,i))
1109 {
1110 for(int32_t k=0; k<8; k+=2)
1111 for(int32_t j=0; j<8; j+=2)
1112 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1113 }
1114 else
1115 {
1116 int32_t color = COLOR_SOLID;
1117
1118 if(isstepable(MAPCOMBO(cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || (combo_class_buf[combobuf[MAPCOMBO(cx,cy)].type].water==0 && combo_class_buf[c.type].water==0)))
1119 color=vc(6);
1120 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(cx,cy,i))
1121 color=vc(7);
1122
1123 rectfill(dest,tx,ty,tx+7,ty+7,color);
1124 }
1125 }
1126 }
1127
1128 bridgedetected = 0;
1129 for(int32_t i=0; i<4; i++)
1130 {
1131 int32_t tx2=((i&2)<<2)+cx;
1132 int32_t ty2=((i&1)<<3)+cy;
1133 for (int32_t m = 0; m <= 1; m++)
1134 {
1135 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1136 {
1137 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && !(combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(1<<i)))
1138 {
1139 bridgedetected |= (1<<i);
1140 }
1141 }
1142 else
1143 {
1144 if (combobuf[MAPCOMBO2(m,tx2,ty2)].type == cBRIDGE && (combobuf[MAPCOMBO2(m,tx2,ty2)].walk&(0x10<<i)))
1145 {
1146 bridgedetected |= (1<<i);
1147 }
1148 }
1149 }
1150 }
1151
1152 // Draw damage combos
1153 newcombo const& c0 = combobuf[MAPCOMBO2(-1,cx,cy)];
1154 newcombo const& c1 = combobuf[MAPCOMBO2(0,cx,cy)];
1155 newcombo const& c2 = combobuf[MAPCOMBO2(1,cx,cy)];
1156 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1157 || combo_class_buf[c1.type].modify_hp_amount
1158 || combo_class_buf[c2.type].modify_hp_amount;
1159
1160 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1161
1162 if(dmg)
1163 {
1164 if (bridgedetected <= 0)
1165 {
1166 for(int32_t k=0; k<16; k+=2)
1167 for(int32_t j=0; j<16; j+=2)
1168 if(((k+j)/2)%2)
1169 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1170 }
1171 else
1172 {
1173 for(int32_t i=0; i<4; i++)
1174 {
1175 if (!(bridgedetected & (1<<i)))
1176 {
1177 int32_t tx=((i&2)<<2)+x;
1178 int32_t ty=((i&1)<<3)+y;
1179 for(int32_t k=0; k<8; k+=2)
1180 for(int32_t j=0; j<8; j+=2)
1181 if(((k+j)/2)%2)
1182 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1183 }
1184 }
1185 }
1186 }
1187
1188 if(c.type == cSLOPE)
1189 {
1190 slope_info s(c, x, y);
1191 s.draw(dest, 0, 0, COLOR_SLOPE);
1192 }
1193 auto fl0 = MAPFLAG2(-1,cx,cy);
1194 auto fl1 = MAPFLAG2(0,cx,cy);
1195 auto fl2 = MAPFLAG2(1,cx,cy);
1196 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1197 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1198 {
1199 bool top = false;
1200 if(cy)
1201 {
1202 top = true;
1203 if(combobuf[MAPCOMBO2(-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1204 || combobuf[MAPCOMBO2(0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1205 || combobuf[MAPCOMBO2(1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1206 || MAPFLAG2(-1,cx,cy) == mfSIDEVIEWLADDER
1207 || MAPFLAG2(0,cx,cy) == mfSIDEVIEWLADDER
1208 || MAPFLAG2(1,cx,cy) == mfSIDEVIEWLADDER)
1209 {
1210 top = false;
1211 }
1212 }
1213 draw_ladder(dest,x,y,COLOR_LADDER,top);
1214 }
1215 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1216 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1217 {
1218 draw_platform(dest,x,y,COLOR_LADDER);
1219 }
1220 }
1221
1222 void zmap::put_walkflags_layered_external(BITMAP *dest,int32_t x,int32_t y,int32_t pos,int32_t layer, int32_t map, int32_t screen)
1223 {
1224 int32_t cx = COMBOX(pos);
1225 int32_t cy = COMBOY(pos);
1226
1227 if (screen < 0) return;
1228 if (map < 0) return;
1229
1230 newcombo const& c = combobuf[MAPCOMBO3(map, screen, layer, pos)];
1231
1232 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1233
1234 int32_t bridgedetected = 0;
1235 for(int32_t i=0; i<4; i++)
1236 {
1237 int32_t tx=((i&2)<<2)+x;
1238 int32_t ty=((i&1)<<3)+y;
1239 int32_t tx2=((i&2)<<2)+cx;
1240 int32_t ty2=((i&1)<<3)+cy;
1241 for (int32_t m = layer; m <= 1; m++)
1242 {
1243 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1244 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1245 {
1246 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1247 {
1248 bridgedetected |= (1<<i);
1249 }
1250 }
1251 else
1252 {
1253 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1254 {
1255 bridgedetected |= (1<<i);
1256 }
1257 }
1258 }
1259 if (bridgedetected & (1<<i))
1260 {
1261 continue;
1262 }
1263 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && (layer==-1 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 0) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 1)) && combo_class_buf[c.type].water!=0 && get_qr(qr_DROWN))
1264 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1265
1266
1267 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1268 {
1269 for(int32_t k=0; k<8; k+=2)
1270 for(int32_t j=0; j<8; j+=2)
1271 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1272 }
1273 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1274 {
1275 if(c.type==cLADDERHOOKSHOT && isstepable(MAPCOMBO3(map, screen, layer, cx,cy)) && ishookshottable(map, screen, cx,cy,i) && layer < 0)
1276 {
1277 for(int32_t k=0; k<8; k+=2)
1278 for(int32_t j=0; j<8; j+=2)
1279 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1280 }
1281 else
1282 {
1283 int32_t color = COLOR_SOLID;
1284
1285 if(isstepable(MAPCOMBO3(map, screen, -1, cx,cy)) && (!get_qr(qr_NO_SOLID_SWIM) || combo_class_buf[combobuf[MAPCOMBO3(map, screen, -1, cx,cy)].type].water==0))
1286 color=vc(6);
1287 else if((c.type==cHOOKSHOTONLY || c.type==cLADDERHOOKSHOT) && ishookshottable(map, screen, cx,cy,i))
1288 color=vc(7);
1289
1290 rectfill(dest,tx,ty,tx+7,ty+7,color);
1291 }
1292 }
1293 }
1294
1295 bridgedetected = 0;
1296 for(int32_t i=0; i<4; i++)
1297 {
1298 int32_t tx2=((i&2)<<2)+cx;
1299 int32_t ty2=((i&1)<<3)+cy;
1300 for (int32_t m = 0; m <= 1; m++)
1301 {
1302 newcombo const& cmb = combobuf[MAPCOMBO3(map, screen, m,tx2,ty2)];
1303 if (get_qr(qr_OLD_BRIDGE_COMBOS))
1304 {
1305 if (cmb.type == cBRIDGE && !(cmb.walk&(1<<i)))
1306 {
1307 bridgedetected |= (1<<i);
1308 }
1309 }
1310 else
1311 {
1312 if (cmb.type == cBRIDGE && (cmb.walk&(0x10<<i)))
1313 {
1314 bridgedetected |= (1<<i);
1315 }
1316 }
1317 }
1318 }
1319
1320 // Draw damage combos
1321 newcombo const& c0 = combobuf[MAPCOMBO3(map, screen, -1,pos)];
1322 newcombo const& c1 = combobuf[MAPCOMBO3(map, screen, 0,pos)];
1323 newcombo const& c2 = combobuf[MAPCOMBO3(map, screen, 1,pos)];
1324 bool dmg = combo_class_buf[c0.type].modify_hp_amount
1325 || combo_class_buf[c1.type].modify_hp_amount
1326 || combo_class_buf[c2.type].modify_hp_amount;
1327
1328 if (combo_class_buf[c2.type].modify_hp_amount) bridgedetected = 0;
1329
1330 if(dmg)
1331 {
1332 if (bridgedetected <= 0)
1333 {
1334 for(int32_t k=0; k<16; k+=2)
1335 for(int32_t j=0; j<16; j+=2)
1336 if(((k+j)/2)%2)
1337 rectfill(dest,x+k,y+j,x+k+1,y+j+1,vc(14));
1338 }
1339 else
1340 {
1341 for(int32_t i=0; i<4; i++)
1342 {
1343 if (!(bridgedetected & (1<<i)))
1344 {
1345 int32_t tx=((i&2)<<2)+x;
1346 int32_t ty=((i&1)<<3)+y;
1347 for(int32_t k=0; k<8; k+=2)
1348 for(int32_t j=0; j<8; j+=2)
1349 if(((k+j)/2)%2)
1350 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(14));
1351 }
1352 }
1353 }
1354 }
1355
1356 if(c.type == cSLOPE)
1357 {
1358 slope_info s(c, x, y);
1359 s.draw(dest, 0, 0, COLOR_SLOPE);
1360 }
1361 auto fl0 = MAPFLAG3(map,screen,-1,pos);
1362 auto fl1 = MAPFLAG3(map,screen,0,pos);
1363 auto fl2 = MAPFLAG3(map,screen,1,pos);
1364 if(fl0 == mfSIDEVIEWLADDER || fl1 == mfSIDEVIEWLADDER || fl2 == mfSIDEVIEWLADDER
1365 || c0.flag == mfSIDEVIEWLADDER || c1.flag == mfSIDEVIEWLADDER || c2.flag == mfSIDEVIEWLADDER)
1366 {
1367 bool top = false;
1368 if(cy)
1369 {
1370 top = true;
1371 if(combobuf[MAPCOMBO3(map,screen,-1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1372 || combobuf[MAPCOMBO3(map,screen,0,cx,cy-16)].flag == mfSIDEVIEWLADDER
1373 || combobuf[MAPCOMBO3(map,screen,1,cx,cy-16)].flag == mfSIDEVIEWLADDER
1374 || MAPFLAG3(map,screen,-1,cx,cy-16) == mfSIDEVIEWLADDER
1375 || MAPFLAG3(map,screen,0,cx,cy-16) == mfSIDEVIEWLADDER
1376 || MAPFLAG3(map,screen,1,cx,cy-16) == mfSIDEVIEWLADDER)
1377 {
1378 top = false;
1379 }
1380 }
1381 draw_ladder(dest,x,y,COLOR_LADDER,top);
1382 }
1383 else if(fl0 == mfSIDEVIEWPLATFORM || fl1 == mfSIDEVIEWPLATFORM || fl2 == mfSIDEVIEWPLATFORM
1384 || c0.flag == mfSIDEVIEWPLATFORM || c1.flag == mfSIDEVIEWPLATFORM || c2.flag == mfSIDEVIEWPLATFORM)
1385 {
1386 draw_platform(dest,x,y,COLOR_LADDER);
1387 }
1388 }
1389
1390 void put_walkflags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t layer)
1391 {
1392 const newcombo& c = combobuf[cmbdat];
1393
1394 if (c.type == cBRIDGE && get_qr(qr_OLD_BRIDGE_COMBOS)) return;
1395
1396 for(int32_t i=0; i<4; i++)
1397 {
1398 int32_t tx=((i&2)<<2)+x;
1399 int32_t ty=((i&1)<<3)+y;
1400
1401 if(!(c.walk&(1<<i) && ((c.usrflags&cflag3) || (c.usrflags&cflag4))) && combo_class_buf[c.type].water!=0)
1402 {
1403 if ((layer==0 || (get_qr(qr_WATER_ON_LAYER_1) && layer == 1) || (get_qr(qr_WATER_ON_LAYER_2) && layer == 2)) && get_qr(qr_DROWN))
1404 {
1405 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1406 }
1407 else
1408 {
1409 rectfill(dest,tx,ty,tx+7,ty+7,vc(11));
1410 }
1411 }
1412
1413
1414 if ((c.walk&(1<<(i+4))) && ((c.walk&(1<<i) && ((c.usrflags&cflag4)) && c.type == cWATER) || c.type == cSHALLOWWATER))
1415 {
1416 for(int32_t k=0; k<8; k+=2)
1417 for(int32_t j=0; j<8; j+=2)
1418 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(11));
1419 }
1420 if(c.walk&(1<<i) && !(combo_class_buf[c.type].water!=0 && ((c.usrflags&cflag3) || (c.usrflags&cflag4))))
1421 {
1422 if(c.type==cLADDERHOOKSHOT)
1423 {
1424 for(int32_t k=0; k<8; k+=2)
1425 for(int32_t j=0; j<8; j+=2)
1426 rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(6+((k+j)/2)%2));
1427 }
1428 else
1429 {
1430 int32_t color = COLOR_SOLID;
1431
1432 if(c.type==cLADDERONLY)
1433 color=vc(6);
1434 else if(c.type==cHOOKSHOTONLY)
1435 color=vc(7);
1436
1437 rectfill(dest,tx,ty,tx+7,ty+7,color);
1438 }
1439 }
1440
1441 // Draw damage combos
1442 if(combo_class_buf[c.type].modify_hp_amount != 0)
1443 {
1444 for(int32_t k=0; k<8; k+=2)
1445 for(int32_t j=0; j<8; j+=2)
1446 if(((k+j)/2)%2) rectfill(dest,tx+k,ty+j,tx+k+1,ty+j+1,vc(4));
1447 }
1448 }
1449
1450 if(c.type == cSLOPE)
1451 {
1452 slope_info s(c, 0, 0);
1453 zfix const& slope = s.slope();
1454
1455 BITMAP* sub = create_bitmap_ex(8,16,16);
1456 clear_bitmap(sub);
1457 s.draw(sub, 0, 0, COLOR_SLOPE);
1458 masked_blit(sub, dest, 0, 0, x, y, 16, 16);
1459 destroy_bitmap(sub);
1460 }
1461 if(c.flag == mfSIDEVIEWLADDER)
1462 {
1463 draw_ladder(dest,x,y,COLOR_LADDER);
1464 }
1465 else if(c.flag == mfSIDEVIEWPLATFORM)
1466 {
1467 draw_platform(dest,x,y,COLOR_LADDER);
1468 }
1469 }
1470
1471 void put_flag(BITMAP* dest, int32_t x, int32_t y, int32_t flag)
1472 {
1473 rectfill(dest,x,y,x+15,y+15,vc(flag&15));
1474 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(flag&15)),-1,"%d",flag);
1475 }
1476 void put_flags(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1477 {
1478
1479 newcombo const& c = combobuf[cmbdat];
1480
1481 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1482 {
1483 // rectfill(dest,x,y,x+15,y+15,vc(cmbdat>>10+1));
1484 // text_mode(-1);
1485 // textprintf_ex(dest,get_zc_font(font_sfont),x+1,y+1,(sflag)==0x7800?vc(0):vc(15),-1,"%d",sflag);
1486 if(sflag)
1487 {
1488 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1489 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1490 }
1491
1492 if(c.flag)
1493 {
1494 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1495 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1496 }
1497 }
1498
1499 if(flags&cCSET)
1500 {
1501 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1502 // text_mode(inv?vc(15):vc(0));
1503 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1504 }
1505 else if(flags&cCTYPE)
1506 {
1507 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1508 // text_mode(inv?vc(15):vc(0));
1509 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1510 }
1511 }
1512
1513 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag,int32_t scale)
1514 {
1515 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
1516
1517 BITMAP* b = create_bitmap_ex(8,scale*16,scale*16);
1518 if(repos)
1519 {
1520 combotile_override_x = x+(8*(scale-1));
1521 combotile_override_y = y+(8*(scale-1));
1522 }
1523 put_combo(b,0,0,cmbdat,cset,flags,sflag);
1524 if(repos) combotile_override_x = combotile_override_y = -1;
1525 masked_stretch_blit(b,dest,0,0,16,16,x,y,16*scale,16*scale);
1526 destroy_bitmap(b);
1527 }
1528 void put_combo(BITMAP *dest,int32_t x,int32_t y,word cmbdat,int32_t cset,int32_t flags,int32_t sflag)
1529 {
1530 static newcombo nilcombo;
1531 nilcombo.tile = 0;
1532
1533 newcombo const& c = cmbdat < MAXCOMBOS ? combobuf[cmbdat] : nilcombo;
1534
1535 if(c.tile==0)
1536 {
1537 rectfill(dest,x,y,x+15,y+15,vc(0));
1538 rectfill(dest,x+3,y+3,x+12,y+12,vc(4));
1539 return;
1540 }
1541
1542 putcombo(dest,x,y,cmbdat,cset);
1543
1544 if((flags&cFLAGS)&&(sflag||combobuf[cmbdat].flag))
1545 {
1546 if(sflag)
1547 {
1548 rectfill(dest,x,y,x+15,y+15,vc(sflag&15));
1549 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-(sflag&15)),-1,"%d",sflag);
1550 }
1551
1552 if(combobuf[cmbdat].flag)
1553 {
1554 rectfill(dest,x,y+(sflag?8:0),x+15,y+15,vc((combobuf[cmbdat].flag)&15));
1555 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+1,vc(15-((combobuf[cmbdat].flag)&15)),-1,"%d",combobuf[cmbdat].flag);
1556 }
1557 }
1558
1559 if(flags&cWALK)
1560 {
1561 put_walkflags(dest,x,y,cmbdat,0);
1562 }
1563
1564 if(flags&cCSET)
1565 {
1566 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1567 // text_mode(inv?vc(15):vc(0));
1568 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+9,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",cset);
1569 }
1570 else if(flags&cCTYPE)
1571 {
1572 bool inv = (((cmbdat&0x7800)==0x7800)&&(flags&cFLAGS));
1573 // text_mode(inv?vc(15):vc(0));
1574 textprintf_ex(dest,get_zc_font(font_z3smallfont),x+1,y+9,inv?vc(0):vc(15),inv?vc(15):vc(0),"%d",c.type);
1575 }
1576 }
1577 void put_engraving(BITMAP* dest, int32_t x, int32_t y, int32_t slot, int32_t scale)
1578 {
1579 auto blitx = 1 + (slot % 16) * 17;
1580 auto blity = 1 + (slot / 16) * 17;
1581 masked_stretch_blit(asset_engravings_bmp, dest, blitx, blity, 16, 16, x, y, 16 * scale, 16 * scale);
1582 }
1583
1584
1585 void copy_mapscr(mapscr *dest, const mapscr *src)
1586 {
1587 if(!dest || !src) return;
1588 *dest = *src;
1589 }
1590
1591 void zmap::put_door(BITMAP *dest,int32_t pos,int32_t side,int32_t type,int32_t xofs,int32_t yofs,bool ignorepos, int32_t scr)
1592 {
1593 int32_t x=0,y=0;
1594 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1595
1596 switch(side)
1597 {
1598 case up:
1599 case down:
1600 x=((pos&15)<<4)+xofs;
1601 y=(ignorepos?0:(pos&0xF0))+yofs;
1602 break;
1603
1604 case left:
1605 case right:
1606 x=(ignorepos?0:((pos&15)<<4))+xofs;
1607 y=(pos&0xF0)+yofs;
1608 break;
1609 }
1610
1611 switch(type)
1612 {
1613 case dt_lock:
1614 case dt_shut:
1615 case dt_boss:
1616 case dt_bomb:
1617 switch(side)
1618 {
1619 case up:
1620 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][0],
1621 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][0],0,0);
1622 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][1],
1623 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][1],0,0);
1624 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][2],
1625 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][2],0,0);
1626 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_u[type][3],
1627 DoorComboSets[doorscreen->door_combo_set].doorcset_u[type][3],0,0);
1628 break;
1629
1630 case down:
1631 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][0],
1632 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][0],0,0);
1633 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][1],
1634 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][1],0,0);
1635 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][2],
1636 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][2],0,0);
1637 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_d[type][3],
1638 DoorComboSets[doorscreen->door_combo_set].doorcset_d[type][3],0,0);
1639 break;
1640
1641 case left:
1642 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][0],
1643 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][0],0,0);
1644 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][2],
1645 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][2],0,0);
1646 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][4],
1647 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][4],0,0);
1648
1649 if(x+16 >= dest->w)
1650 break;
1651
1652 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][1],
1653 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][1],0,0);
1654 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][3],
1655 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][3],0,0);
1656 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_l[type][5],
1657 DoorComboSets[doorscreen->door_combo_set].doorcset_l[type][5],0,0);
1658 break;
1659
1660 case right:
1661
1662 put_combo(dest,x+16,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][1],
1663 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][1],0,0);
1664 put_combo(dest,x+16,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][3],
1665 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][3],0,0);
1666 put_combo(dest,x+16,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][5],
1667 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][5],0,0);
1668
1669 if(x+16 <= 0)
1670 break;
1671
1672 put_combo(dest,x,y,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][0],
1673 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][0],0,0);
1674 put_combo(dest,x,y+16,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][2],
1675 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][2],0,0);
1676 put_combo(dest,x,y+32,DoorComboSets[doorscreen->door_combo_set].doorcombo_r[type][4],
1677 DoorComboSets[doorscreen->door_combo_set].doorcset_r[type][4],0,0);
1678 break;
1679 }
1680
1681 break;
1682
1683 case dt_pass:
1684 case dt_wall:
1685 case dt_walk:
1686 default:
1687 break;
1688 }
1689 }
1690
1691 void zmap::over_door(BITMAP *dest,int32_t pos,int32_t side,int32_t xofs,int32_t yofs,bool, int32_t scr)
1692 {
1693 int32_t x=((pos&15)<<4)+xofs;
1694 int32_t y=(pos&0xF0)+yofs;
1695 mapscr *doorscreen=(prv_mode?get_prvscr():screens+scr);
1696
1697
1698 switch(side)
1699 {
1700 case up:
1701 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0]!=0)
1702 {
1703 overcombo(dest,x,y,
1704 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[0],
1705 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[0]);
1706 }
1707
1708 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1]!=0)
1709 {
1710 overcombo(dest,x+16,y,
1711 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_u[1],
1712
1713 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_u[1]);
1714 }
1715
1716 break;
1717
1718 case down:
1719 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0]!=0)
1720 {
1721 overcombo(dest,x,y,
1722 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[0],
1723 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[0]);
1724 }
1725
1726 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1]!=0)
1727 {
1728 overcombo(dest,x+16,y,
1729 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_d[1],
1730 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_d[1]);
1731 }
1732
1733 break;
1734
1735 case left:
1736 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0]!=0)
1737 {
1738 overcombo(dest,x,y,
1739 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[0],
1740 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[0]);
1741 }
1742
1743 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1]!=0)
1744 {
1745 overcombo(dest,x,y+16,
1746 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[1],
1747 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[1]);
1748 }
1749
1750 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2]!=0)
1751 {
1752 overcombo(dest,x,y+32,
1753 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_l[2],
1754 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_l[2]);
1755 }
1756
1757 break;
1758
1759 case right:
1760 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0]!=0)
1761 {
1762 overcombo(dest,x,y,
1763 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[0],
1764 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[0]);
1765 }
1766
1767 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1]!=0)
1768 {
1769 overcombo(dest,x,y+16,
1770
1771 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[1],
1772 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[1]);
1773 }
1774
1775 if(DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2]!=0)
1776 {
1777 overcombo(dest,x,y+32,
1778 DoorComboSets[doorscreen->door_combo_set].bombdoorcombo_r[2],
1779 DoorComboSets[doorscreen->door_combo_set].bombdoorcset_r[2]);
1780 }
1781
1782 break;
1783 }
1784 }
1785
1786 bool zmap::misaligned(int32_t map, int32_t screen, int32_t i, int32_t dir)
1787 {
1788 word cmbcheck1, cmbcheck2;
1789 newcombo combocheck1, combocheck2;
1790 combocheck1 = combobuf[0];
1791 combocheck2 = combobuf[0];
1792 combocheck1.walk = 0;
1793 combocheck2.walk = 0;
1794
1795 int32_t layermap, layerscreen;
1796
1797 switch(dir)
1798 {
1799 case up:
1800 {
1801 if(i>15) //not top row of combos
1802 {
1803 return false;
1804 }
1805
1806 if(screen<16) //top row of screens
1807 {
1808 return false;
1809
1810 }
1811
1812 //check main screen
1813 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1814 cmbcheck2 = vbound(AbsoluteScr(map, screen-16)->data[i+160], 0, MAXCOMBOS-1);
1815 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1816 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1817
1818 //check layer 1
1819 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1820
1821 if(layermap>-1 && layermap<map_count)
1822 {
1823 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1824 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1825 if (combobuf[cmbcheck1].type == cBRIDGE)
1826 {
1827 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1828 {
1829 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1830 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1831 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1832 }
1833 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1834 }
1835 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1836 }
1837
1838 layermap=AbsoluteScr(map, screen-16)->layermap[0]-1;
1839
1840 if(layermap>-1 && layermap<map_count)
1841 {
1842 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[0];
1843 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1844 if (combobuf[cmbcheck2].type == cBRIDGE)
1845 {
1846 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1847 {
1848 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1849 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1850 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1851 }
1852 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1853 }
1854 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1855 }
1856
1857 //check layer 2
1858 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1859
1860 if(layermap>-1 && layermap<map_count)
1861 {
1862 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1863
1864 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1865 if (combobuf[cmbcheck2].type == cBRIDGE)
1866 {
1867 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1868 {
1869 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1870 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1871 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1872 }
1873 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1874 }
1875 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1876 }
1877
1878 layermap=AbsoluteScr(map, screen-16)->layermap[1]-1;
1879
1880 if(layermap>-1 && layermap<map_count)
1881 {
1882 layerscreen=AbsoluteScr(map, screen-16)->layerscreen[1];
1883 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+160];
1884 if (combobuf[cmbcheck2].type == cBRIDGE)
1885 {
1886 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1887 {
1888 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1889 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1890 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1891 }
1892 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1893 }
1894 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1895 }
1896
1897 if(((combocheck1.walk&5)*2)!=(combocheck2.walk&10))
1898 {
1899 return true;
1900 }
1901
1902 break;
1903 }
1904 case down:
1905 {
1906 if(i<160) //not bottom row of combos
1907 {
1908 return false;
1909 }
1910
1911 if(screen>111) //bottom row of screens
1912 {
1913 return false;
1914 }
1915
1916 //check main screen
1917 cmbcheck1 = vbound(AbsoluteScr(map, screen)->data[i], 0, MAXCOMBOS-1);
1918 cmbcheck2 = vbound(AbsoluteScr(map, screen+16)->data[i-160], 0, MAXCOMBOS-1);
1919 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
1920 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
1921
1922
1923 //check layer 1
1924 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
1925
1926 if(layermap>-1 && layermap<map_count)
1927 {
1928 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
1929 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1930 if (combobuf[cmbcheck1].type == cBRIDGE)
1931 {
1932 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1933 {
1934 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1935 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1936 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1937 }
1938 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1939 }
1940 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1941 }
1942
1943 layermap=AbsoluteScr(map, screen+16)->layermap[0]-1;
1944
1945 if(layermap>-1 && layermap<map_count)
1946 {
1947 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[0];
1948 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1949 if (combobuf[cmbcheck2].type == cBRIDGE)
1950 {
1951 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1952 {
1953 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1954 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1955 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1956 }
1957 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1958 }
1959 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1960 }
1961
1962 //check layer 2
1963 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
1964
1965 if(layermap>-1 && layermap<map_count)
1966 {
1967 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
1968 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
1969 if (combobuf[cmbcheck1].type == cBRIDGE)
1970 {
1971 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1972 {
1973 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
1974 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
1975 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
1976 }
1977 else combocheck1.walk&=combobuf[cmbcheck1].walk;
1978 }
1979 else combocheck1.walk|=combobuf[cmbcheck1].walk;
1980 }
1981
1982 layermap=AbsoluteScr(map, screen+16)->layermap[1]-1;
1983
1984 if(layermap>-1 && layermap<map_count)
1985 {
1986 layerscreen=AbsoluteScr(map, screen+16)->layerscreen[1];
1987 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-160];
1988 if (combobuf[cmbcheck2].type == cBRIDGE)
1989 {
1990 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
1991 {
1992 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
1993 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
1994 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
1995 }
1996 else combocheck2.walk&=combobuf[cmbcheck2].walk;
1997 }
1998 else combocheck2.walk|=combobuf[cmbcheck2].walk;
1999 }
2000
2001 if((combocheck1.walk&10)!=((combocheck2.walk&5)*2))
2002 {
2003 return true;
2004 }
2005
2006 break;
2007 }
2008 case left:
2009 {
2010 if((i&0xF)!=0) //not left column of combos
2011 {
2012 return false;
2013 }
2014
2015 if((screen&0xF)==0) //left column of screens
2016 {
2017 return false;
2018 }
2019
2020 //check main screen
2021 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2022 cmbcheck2 = AbsoluteScr(map, screen-1)->data[i+15];
2023 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2024 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2025
2026 //check layer 1
2027 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2028
2029 if(layermap>-1 && layermap<map_count)
2030 {
2031 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2032 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2033 if (combobuf[cmbcheck1].type == cBRIDGE)
2034 {
2035 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2036 {
2037 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2038 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2039 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2040 }
2041 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2042 }
2043 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2044 }
2045
2046 layermap=AbsoluteScr(map, screen-1)->layermap[0]-1;
2047
2048 if(layermap>-1 && layermap<map_count)
2049 {
2050 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[0];
2051 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2052 if (combobuf[cmbcheck2].type == cBRIDGE)
2053 {
2054 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2055 {
2056 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2057 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2058 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2059 }
2060 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2061 }
2062 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2063 }
2064
2065 //check layer 2
2066 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2067
2068 if(layermap>-1 && layermap<map_count)
2069 {
2070 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2071 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2072 if (combobuf[cmbcheck1].type == cBRIDGE)
2073 {
2074 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2075 {
2076 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2077 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2078 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2079 }
2080 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2081 }
2082 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2083 }
2084
2085 layermap=AbsoluteScr(map, screen-1)->layermap[1]-1;
2086
2087 if(layermap>-1 && layermap<map_count)
2088 {
2089 layerscreen=AbsoluteScr(map, screen-1)->layerscreen[1];
2090 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i+15];
2091 if (combobuf[cmbcheck2].type == cBRIDGE)
2092 {
2093 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2094 {
2095 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2096 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2097 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2098 }
2099 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2100 }
2101 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2102 }
2103
2104 if(((combocheck1.walk&3)*4)!=(combocheck2.walk&12))
2105 {
2106 return true;
2107 }
2108
2109 break;
2110 }
2111 case right:
2112 {
2113 if((i&0xF)!=15) //not right column of combos
2114 {
2115 return false;
2116 }
2117
2118 if((screen&0xF)==15) //right column of screens
2119 {
2120 return false;
2121 }
2122
2123 //check main screen
2124 cmbcheck1 = AbsoluteScr(map, screen)->data[i];
2125 cmbcheck2 = AbsoluteScr(map, screen+1)->data[i-15];
2126 if (combobuf[cmbcheck1].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck1.walk|=combobuf[cmbcheck1].walk;
2127 if (combobuf[cmbcheck2].type != cBRIDGE || !get_qr(qr_OLD_BRIDGE_COMBOS)) combocheck2.walk|=combobuf[cmbcheck2].walk;
2128
2129 //check layer 1
2130 layermap=AbsoluteScr(map, screen)->layermap[0]-1;
2131
2132 if(layermap>-1 && layermap<map_count)
2133 {
2134 layerscreen=AbsoluteScr(map, screen)->layerscreen[0];
2135 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2136 if (combobuf[cmbcheck1].type == cBRIDGE)
2137 {
2138 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2139 {
2140 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2141 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2142 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2143 }
2144 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2145 }
2146 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2147 }
2148
2149 layermap=AbsoluteScr(map, screen+1)->layermap[0]-1;
2150
2151 if(layermap>-1 && layermap<map_count)
2152 {
2153 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[0];
2154 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2155 if (combobuf[cmbcheck2].type == cBRIDGE)
2156 {
2157 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2158 {
2159 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2160 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2161 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2162 }
2163 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2164 }
2165 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2166 }
2167
2168 //check layer 2
2169 layermap=AbsoluteScr(map, screen)->layermap[1]-1;
2170
2171 if(layermap>-1 && layermap<map_count)
2172 {
2173 layerscreen=AbsoluteScr(map, screen)->layerscreen[1];
2174 cmbcheck1 = AbsoluteScr(layermap, layerscreen)->data[i];
2175 if (combobuf[cmbcheck1].type == cBRIDGE)
2176 {
2177 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2178 {
2179 int efflag = (combobuf[cmbcheck1].walk & 0xF0)>>4;
2180 int newsolid = (combobuf[cmbcheck1].walk & 0xF);
2181 combocheck1.walk = ((newsolid | combocheck1.walk) & (~efflag)) | (newsolid & efflag);
2182 }
2183 else combocheck1.walk&=combobuf[cmbcheck1].walk;
2184 }
2185 else combocheck1.walk|=combobuf[cmbcheck1].walk;
2186 }
2187
2188 layermap=AbsoluteScr(map, screen+1)->layermap[1]-1;
2189
2190 if(layermap>-1 && layermap<map_count)
2191 {
2192 layerscreen=AbsoluteScr(map, screen+1)->layerscreen[1];
2193
2194 cmbcheck2 = AbsoluteScr(layermap, layerscreen)->data[i-15];
2195 if (combobuf[cmbcheck2].type == cBRIDGE)
2196 {
2197 if (!get_qr(qr_OLD_BRIDGE_COMBOS))
2198 {
2199 int efflag = (combobuf[cmbcheck2].walk & 0xF0)>>4;
2200 int newsolid = (combobuf[cmbcheck2].walk & 0xF);
2201 combocheck2.walk = ((newsolid | combocheck2.walk) & (~efflag)) | (newsolid & efflag);
2202 }
2203 else combocheck2.walk&=combobuf[cmbcheck2].walk;
2204 }
2205 else combocheck2.walk|=combobuf[cmbcheck2].walk;
2206 }
2207
2208 if((combocheck1.walk&12)!=((combocheck2.walk&3)*4))
2209 {
2210 return true;
2211 }
2212
2213 break;
2214 }
2215 }
2216
2217 return false;
2218 }
2219
2220 void zmap::check_alignments(BITMAP* dest,int32_t x,int32_t y,int32_t scr)
2221 {
2222 int32_t checkcombo;
2223
2224 if(alignment_arrow_timer>31)
2225 {
2226 if(scr<0)
2227 {
2228 scr=cursor.screen;
2229 }
2230
2231 if((scr<128)) //do the misalignment arrows
2232 {
2233 for(checkcombo=1; checkcombo<15; checkcombo++) //check the top row (except the corners)
2234 {
2235 if(misaligned(cursor.map, scr, checkcombo, up))
2236 {
2237 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2238 }
2239 }
2240
2241 for(checkcombo=161; checkcombo<175; checkcombo++) //check the top row (except the corners)
2242 {
2243 if(misaligned(cursor.map, scr, checkcombo, down))
2244 {
2245 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2246 }
2247 }
2248
2249 for(checkcombo=16; checkcombo<160; checkcombo+=16) //check the left side (except the corners)
2250 {
2251 if(misaligned(cursor.map, scr, checkcombo, left))
2252 {
2253 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2254 }
2255 }
2256
2257 for(checkcombo=31; checkcombo<175; checkcombo+=16) //check the right side (except the corners)
2258 {
2259 if(misaligned(cursor.map, scr, checkcombo, right))
2260 {
2261 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2262 }
2263 }
2264
2265 int32_t tempalign;
2266
2267 //check top left corner
2268 checkcombo=0;
2269 tempalign=0;
2270 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2271 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2272
2273 switch(tempalign)
2274 {
2275 case 0:
2276 break;
2277
2278 case 1: //up
2279 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2280 break;
2281
2282 case 2: //left
2283 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2284 break;
2285
2286 case 3: //up-left
2287 masked_blit(arrow_bmp[4],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2288 break;
2289 }
2290
2291 //check top right corner
2292 checkcombo=15;
2293 tempalign=0;
2294 tempalign+=(misaligned(cursor.map, scr, checkcombo, up))?1:0;
2295 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2296
2297 switch(tempalign)
2298 {
2299 case 0:
2300 break;
2301
2302 case 1: //up
2303 masked_blit(arrow_bmp[0],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2304 break;
2305
2306 case 2: //right
2307 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2308 break;
2309
2310 case 3: //up-right
2311 masked_blit(arrow_bmp[5],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2312 break;
2313 }
2314
2315 //check bottom left corner
2316 checkcombo=160;
2317 tempalign=0;
2318 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2319 tempalign+=(misaligned(cursor.map, scr, checkcombo, left))?2:0;
2320
2321 switch(tempalign)
2322 {
2323 case 0:
2324 break;
2325
2326 case 1: //down
2327 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2328 break;
2329
2330 case 2: //left
2331 masked_blit(arrow_bmp[2],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2332 break;
2333
2334 case 3: //down-left
2335 masked_blit(arrow_bmp[6],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2336 break;
2337 }
2338
2339 //check bottom right corner
2340
2341 checkcombo=175;
2342 tempalign=0;
2343 tempalign+=(misaligned(cursor.map, scr, checkcombo, down))?1:0;
2344 tempalign+=(misaligned(cursor.map, scr, checkcombo, right))?2:0;
2345
2346 switch(tempalign)
2347 {
2348 case 0:
2349 break;
2350
2351 case 1: //down
2352 masked_blit(arrow_bmp[1],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2353 break;
2354
2355 case 2: //right
2356 masked_blit(arrow_bmp[3],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2357 break;
2358
2359 case 3: //down-right
2360 masked_blit(arrow_bmp[7],dest,0,0,((checkcombo&15)<<4)+x,(checkcombo&0xF0)+y,16,16);
2361 break;
2362 }
2363 }
2364 }
2365 }
2366
2367 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2368 {
2369 return MAPCOMBO3(map, screen, layer, COMBOPOS(x,y));
2370 }
2371
2372 int32_t zmap::MAPCOMBO3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2373 {
2374 if (map < 0 || screen < 0) return 0;
2375
2376 if(pos>175 || pos < 0)
2377 return 0;
2378
2379 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2380
2381 if (!m->is_valid()) return 0;
2382
2383 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2384
2385 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2386
2387 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2388
2389 if (!scr->is_valid()) return 0;
2390
2391 return scr->data[pos]; // entire combo code
2392 }
2393
2394 // Takes array index layer num., not actual layer num.
2395 int32_t zmap::MAPCOMBO2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2396 {
2397 if(lyr<=-1) return MAPCOMBO(x,y,map,scr);
2398
2399 if(map<0)
2400 map=cursor.map;
2401
2402 if(scr<0)
2403 scr=cursor.screen;
2404
2405 mapscr *screen1;
2406
2407 if(prv_mode)
2408 {
2409 screen1=get_prvscr();
2410 }
2411 else
2412 {
2413 screen1=AbsoluteScr(cursor.map,cursor.screen);
2414 }
2415
2416 int32_t layermap;
2417 layermap=screen1->layermap[lyr]-1;
2418
2419 if(layermap<0 || layermap >= map_count) return 0;
2420
2421 mapscr *layer;
2422
2423 if(prv_mode)
2424 layer = &prvlayers[lyr];
2425 else
2426 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2427
2428 int32_t pos = COMBOPOS(x,y);
2429
2430 if(pos>175 || pos < 0)
2431 return 0;
2432
2433 return layer->data[pos];
2434 }
2435
2436 int32_t zmap::MAPCOMBO(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2437 {
2438 if(map<0)
2439 map=cursor.map;
2440
2441 if(scr<0)
2442 scr=cursor.screen;
2443
2444 mapscr *screen1;
2445
2446 if(prv_mode)
2447 {
2448 screen1=get_prvscr();
2449 }
2450 else
2451 {
2452 screen1=AbsoluteScr(cursor.map,cursor.screen);
2453 }
2454
2455 x = vbound(x, 0, 16*16);
2456 y = vbound(y, 0, 11*16);
2457 int32_t combo = COMBOPOS(x,y);
2458
2459 if(combo>175 || combo < 0)
2460 return 0;
2461
2462 return screen1->data[combo];
2463 }
2464
2465 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t x,int32_t y)
2466 {
2467 return MAPFLAG3(map, screen, layer, COMBOPOS(x,y));
2468 }
2469
2470 int32_t zmap::MAPFLAG3(int32_t map, int32_t screen, int32_t layer, int32_t pos)
2471 {
2472 if (map < 0 || screen < 0) return 0;
2473
2474 if(pos>175 || pos < 0)
2475 return 0;
2476
2477 mapscr const* m = &TheMaps[(map*MAPSCRS)+screen];
2478
2479 if (!m->is_valid()) return 0;
2480
2481 int32_t mapid = (layer < 0 ? -1 : ((m->layermap[layer] - 1) * MAPSCRS + m->layerscreen[layer]));
2482
2483 if (layer >= 0 && (mapid < 0 || mapid > MAXMAPS*MAPSCRS)) return 0;
2484
2485 mapscr const* scr = ((mapid < 0 || mapid > MAXMAPS*MAPSCRS) ? m : &TheMaps[mapid]);
2486
2487 if (!scr->is_valid()) return 0;
2488
2489 return scr->sflag[pos]; // entire combo code
2490 }
2491
2492 int32_t zmap::MAPFLAG2(int32_t lyr,int32_t x,int32_t y, int32_t map, int32_t scr)
2493 {
2494 if(lyr<=-1) return MAPFLAG(x,y,map,scr);
2495
2496 if(map<0)
2497 map=cursor.map;
2498
2499 if(scr<0)
2500 scr=cursor.screen;
2501
2502 mapscr *screen1;
2503
2504 if(prv_mode)
2505 {
2506 screen1=get_prvscr();
2507 }
2508 else
2509 {
2510 screen1=AbsoluteScr(cursor.map,cursor.screen);
2511 }
2512
2513 int32_t layermap;
2514 layermap=screen1->layermap[lyr]-1;
2515
2516 if(layermap<0 || layermap >= map_count) return 0;
2517
2518 mapscr *layer;
2519
2520 if(prv_mode)
2521 layer = &prvlayers[lyr];
2522 else
2523 layer = AbsoluteScr(layermap,screen1->layerscreen[lyr]);
2524
2525 int32_t combo = COMBOPOS(x,y);
2526
2527 if(combo>175 || combo < 0)
2528 return 0;
2529
2530 return layer->sflag[combo];
2531 }
2532
2533 int32_t zmap::MAPFLAG(int32_t x,int32_t y, int32_t map, int32_t scr) //map=-1,scr=-1
2534 {
2535 if(map<0)
2536 map=cursor.map;
2537
2538 if(scr<0)
2539 scr=cursor.screen;
2540
2541 mapscr *screen1;
2542
2543 if(prv_mode)
2544 {
2545 screen1=get_prvscr();
2546 }
2547 else
2548 {
2549 screen1=AbsoluteScr(cursor.map,cursor.screen);
2550 }
2551
2552 x = vbound(x, 0, 16*16);
2553 y = vbound(y, 0, 11*16);
2554 int32_t combo = COMBOPOS(x,y);
2555
2556 if(combo>175 || combo < 0)
2557 return 0;
2558
2559 return screen1->sflag[combo];
2560 }
2561
2562 void zmap::draw_darkness(BITMAP* dest, BITMAP* transdest)
2563 {
2564 mapscr *layers[7];
2565 mapscr *basescr;
2566 if(prv_mode)
2567 {
2568 layers[0] = &prvscr;
2569 basescr = layers[0];
2570 for(auto q = 1; q < 7; ++q)
2571 {
2572 if(prvlayers[q-1].valid)
2573 layers[q] = &(prvlayers[q-1]);
2574 else layers[q] = NULL;
2575 }
2576 }
2577 else
2578 {
2579 layers[0] = AbsoluteScr(cursor.map, cursor.screen);
2580 basescr = layers[0];
2581 for(auto q = 1; q < 7; ++q)
2582 {
2583 int32_t lmap = basescr->layermap[q-1]-1;
2584 int32_t lscr = basescr->layerscreen[q-1];
2585 if(lmap < 0)
2586 layers[q] = NULL;
2587 else layers[q] = AbsoluteScr(lmap, lscr);
2588 }
2589 }
2590 for(auto q = 0; q < 7; ++q)
2591 {
2592 if(!layers[q]) continue;
2593 for(auto pos = 0; pos < 176; ++pos)
2594 {
2595 newcombo const& cmb = combobuf[layers[q]->data[pos]];
2596 if(cmb.type == cTORCH)
2597 do_torch_combo(cmb, COMBOX(pos)+8, COMBOY(pos)+8, dest, transdest);
2598 }
2599 }
2600 word maxffc = basescr->numFFC();
2601 for(auto q = 0; q < maxffc; ++q)
2602 {
2603 newcombo const& cmb = combobuf[basescr->ffcs[q].data];
2604 if(cmb.type == cTORCH)
2605 do_torch_combo(cmb, (basescr->ffcs[q].x.getInt())+(basescr->ffEffectWidth(q)/2), (basescr->ffcs[q].y.getInt())+(basescr->ffEffectHeight(q)/2), dest, transdest);
2606 }
2607 }
2608
2609 void drawcombo(BITMAP* dest, int32_t x, int32_t y, int32_t cid, int32_t cset, int32_t flags,
2610 int32_t sflag, bool over = true, bool transp = false, bool dither = false)
2611 {
2612 newcombo const& cmb = combobuf[cid];
2613 if(cmb.animflags & AF_TRANSPARENT) transp = !transp;
2614 if(dither)
2615 {
2616 if (LayerDitherSz == 0)
2617 return;
2618 BITMAP* buf = create_bitmap_ex(8,16,16);
2619 clear_bitmap(buf);
2620 overcombo(buf,0,0,cid,cset);
2621 ditherblit(buf,nullptr,0,dithChecker,LayerDitherSz,x,y);
2622 if(over)
2623 {
2624 if(transp)
2625 {
2626 color_map = &trans_table2;
2627 draw_trans_sprite(dest, buf, x, y);
2628 color_map = &trans_table;
2629 }
2630 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2631 }
2632 else masked_blit(buf, dest, 0, 0, x, y, 16, 16);
2633 destroy_bitmap(buf);
2634 }
2635 else if(over)
2636 {
2637 if(transp)
2638 overcombotranslucent(dest,x,y,cid,cset,0);
2639 else overcombo(dest,x,y,cid,cset);
2640 }
2641 else put_combo(dest,x,y,cid,cset,flags,sflag);
2642 }
2643 static void _zmap_drawlayer(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool over, bool dither, bool passflag = false)
2644 {
2645 if(!md) return;
2646 for (int32_t i = 0; i < 176; i++)
2647 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, md->data[i], md->cset[i], flags, passflag ? md->sflag[i] : 0, over, trans, dither);
2648 }
2649 static void _zmap_drawlayer_ohead(BITMAP* dest, int32_t x, int32_t y, mapscr* md, int32_t flags, bool trans, bool dither)
2650 {
2651 if(!md) return;
2652 for (int32_t i = 0; i < 176; i++)
2653 {
2654 int data = md->data[i];
2655 if(combo_class_buf[combobuf[data].type].overhead)
2656 drawcombo(dest, ((i&15)<<4)+x, (i&0xF0)+y, data, md->cset[i], 0, 0, true, trans, dither);
2657 }
2658 }
2659 static mapscr* _zmap_get_lyr_checked(int lyr, mapscr* basescr)
2660 {
2661 if(!LayerMaskInt[lyr])
2662 return nullptr;
2663 if(lyr == 0)
2664 return basescr;
2665 int layermap = basescr->layermap[lyr-1]-1;
2666
2667 if(layermap>-1 && layermap<map_count)
2668 {
2669 int layerscreen = layermap*MAPSCRS+basescr->layerscreen[lyr-1];
2670 return &TheMaps[layerscreen];
2671 }
2672 return nullptr;
2673 }
2674 static void _zmap_draw_ffc_layer(BITMAP* dest,int32_t x,int32_t y,int32_t flags,mapscr* basescr, int32_t layer)
2675 {
2676 int num_ffcs = basescr->numFFC();
2677 for(int32_t i=num_ffcs-1; i>=0; i--)
2678 {
2679 auto const& ff = basescr->ffcs[i];
2680 if(ff.data)
2681 {
2682 if(!(ff.flags&ffc_changer))
2683 {
2684 int32_t tx=(ff.x.getInt())+x;
2685 int32_t ty=(ff.y.getInt())+y;
2686
2687 if((ff.flags&ffc_overlay) ? layer == -1 : layer == ff.layer)
2688 {
2689 if(ff.flags&ffc_trans)
2690 overcomboblocktranslucent(dest,tx,ty,ff.data, ff.cset, ff.txsz, ff.tysz,128);
2691 else
2692 overcomboblock(dest, tx, ty, ff.data, ff.cset, ff.txsz, ff.tysz);
2693 }
2694 }
2695 }
2696 }
2697 }
2698 void zmap::draw(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t map,int32_t screen,int32_t hl_layer)
2699 {
2700 #define HL_LAYER(lyr) (!(NoHighlightLayer0 && hl_layer == 0) && hl_layer > -1 && hl_layer != lyr)
2701 int32_t antiflags=(flags&~cFLAGS)&~cWALK;
2702
2703 if(map<0)
2704 map=cursor.map;
2705
2706 if(screen<0)
2707 screen=cursor.screen;
2708
2709 mapscr *basescr;
2710 mapscr* layers[7] = {nullptr};
2711
2712 if(prv_mode)
2713 {
2714 hl_layer = -1;
2715 basescr=get_prvscr();
2716 }
2717 else
2718 {
2719 basescr=AbsoluteScr(map,screen);
2720 }
2721 layers[0] = _zmap_get_lyr_checked(0,basescr);
2722 for(int lyr = 1; lyr < 7; ++lyr)
2723 {
2724 layers[lyr] = prv_mode ? ((&prvlayers[lyr-1])->valid ? &prvlayers[lyr - 1] : nullptr)
2725 : _zmap_get_lyr_checked(lyr,basescr);
2726 }
2727
2728 if(!(basescr->valid&mVALID))
2729 {
2730 // rectfill(dest,x,y,x+255,y+175,dvc(0+1));
2731 rectfill(dest,x,y,x+255,y+175,vc(1));
2732
2733 if(ShowMisalignments)
2734 {
2735 check_alignments(dest,x,y,screen);
2736 }
2737
2738 return;
2739 }
2740
2741 if(LayerMaskInt[0]==0)
2742 {
2743 byte bgfill = 0;
2744 if (LayerDitherBG > -1)
2745 bgfill = vc(LayerDitherBG);
2746 rectfill(dest,x,y,x+255,y+175,bgfill);
2747 }
2748
2749 if(get_qr(qr_CLASSIC_DRAWING_ORDER))
2750 {
2751 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2752 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, false, HL_LAYER(2));
2753 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2754 }
2755
2756 if(XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2757 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG), HL_LAYER(3));
2758 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -3);
2759
2760 if(!get_qr(qr_CLASSIC_DRAWING_ORDER))
2761 {
2762 if(XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2763 _zmap_drawlayer(dest, x, y, layers[2], antiflags, false, true, HL_LAYER(2));
2764 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -2);
2765 }
2766
2767 _zmap_drawlayer(dest, x, y, layers[0], antiflags, false, !get_qr(qr_CLASSIC_DRAWING_ORDER) || (XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG)||XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG)), HL_LAYER(0), true);
2768 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 0);
2769
2770
2771 _zmap_drawlayer(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, true, HL_LAYER(1));
2772 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 1);
2773
2774 if(!XOR(basescr->flags7&fLAYER2BG,ViewLayer2BG))
2775 _zmap_drawlayer(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, true, HL_LAYER(2));
2776 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 2);
2777
2778 int32_t doortype[4];
2779
2780 for(int32_t i=0; i<4; i++)
2781 {
2782 switch(basescr->door[i])
2783 {
2784 case dOPEN:
2785 doortype[i]=dt_pass;
2786 break;
2787
2788 case dLOCKED:
2789 doortype[i]=dt_lock;
2790 break;
2791
2792 case d1WAYSHUTTER:
2793 case dSHUTTER:
2794 doortype[i]=dt_shut;
2795 break;
2796
2797 case dBOSS:
2798 doortype[i]=dt_boss;
2799 break;
2800
2801 case dBOMB:
2802 doortype[i]=dt_bomb;
2803 break;
2804 }
2805 }
2806
2807 switch(basescr->door[up])
2808 {
2809 case dBOMB:
2810 over_door(dest,39,up,x,y,false, screen);
2811 [[fallthrough]];
2812 case dOPEN:
2813 case dLOCKED:
2814 case d1WAYSHUTTER:
2815 case dSHUTTER:
2816 case dBOSS:
2817 put_door(dest,7,up,doortype[up],x,y,false,screen);
2818 break;
2819
2820 case dWALK:
2821 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2822 {
2823 overcombo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2824 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2825 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0]);
2826 }
2827 else
2828
2829 {
2830 put_combo(dest,((23&15)<<4)+8+x,(23&0xF0)+y,
2831 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[0],
2832 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[0],0,0);
2833 }
2834
2835 break;
2836 }
2837
2838 switch(basescr->door[down])
2839 {
2840 case dBOMB:
2841 over_door(dest,135,down,x,y,false,screen);
2842 [[fallthrough]];
2843 case dOPEN:
2844 case dLOCKED:
2845 case d1WAYSHUTTER:
2846 case dSHUTTER:
2847 case dBOSS:
2848 put_door(dest,151,down,doortype[down],x,y,false,screen);
2849 break;
2850
2851 case dWALK:
2852 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2853 {
2854 overcombo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2855 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2856 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1]);
2857 }
2858 else
2859 {
2860 put_combo(dest,((151&15)<<4)+8+x,(151&0xF0)+y,
2861 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[1],
2862 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[1],0,0);
2863 }
2864
2865 break;
2866 }
2867
2868 switch(basescr->door[left])
2869 {
2870 case dBOMB:
2871 over_door(dest,66,left,x,y,false,screen);
2872 [[fallthrough]];
2873 case dOPEN:
2874 case dLOCKED:
2875 case d1WAYSHUTTER:
2876 case dSHUTTER:
2877 case dBOSS:
2878 put_door(dest,64,left,doortype[left],x,y,false,screen);
2879 break;
2880
2881 case dWALK:
2882 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2883 {
2884 overcombo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2885 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2886 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2]);
2887 }
2888 else
2889 {
2890 put_combo(dest,((81&15)<<4)+x,(81&0xF0)+y,
2891 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[2],
2892 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[2],0,0);
2893 }
2894
2895 break;
2896 }
2897
2898 switch(basescr->door[right])
2899 {
2900
2901 case dBOMB:
2902 over_door(dest,77,right,x,y,false,screen);
2903 [[fallthrough]];
2904 case dOPEN:
2905 case dLOCKED:
2906 case d1WAYSHUTTER:
2907 case dSHUTTER:
2908 case dBOSS:
2909 put_door(dest,78,right,doortype[right],x,y,false,screen);
2910 break;
2911
2912 case dWALK:
2913 if(get_bit(DoorComboSets[screens[cursor.screen].door_combo_set].flags,df_walktrans))
2914 {
2915 overcombo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2916 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2917 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3]);
2918 }
2919 else
2920 {
2921 put_combo(dest,((94&15)<<4)+x,(94&0xF0)+y,
2922 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcombo[3],
2923 DoorComboSets[screens[cursor.screen].door_combo_set].walkthroughcset[3],0,0);
2924 }
2925
2926 break;
2927 }
2928
2929 if((basescr->hasitem != 0) && !(flags&cNOITEM))
2930 {
2931 putitem2(dest,basescr->itemx+x,basescr->itemy+y+1-(get_qr(qr_NOITEMOFFSET)),basescr->item,lens_hint_item[basescr->item][0],lens_hint_item[basescr->item][1], 0);
2932 }
2933
2934 if(!XOR(basescr->flags7&fLAYER3BG,ViewLayer3BG))
2935 _zmap_drawlayer(dest, x, y, layers[3], antiflags, basescr->layeropacity[3-1]!=255, true, HL_LAYER(3));
2936 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 3);
2937
2938 _zmap_drawlayer(dest, x, y, layers[4], antiflags, basescr->layeropacity[4-1]!=255, true, HL_LAYER(4));
2939 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 4);
2940
2941 _zmap_drawlayer_ohead(dest, x, y, layers[0], antiflags, false, HL_LAYER(0));
2942
2943 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
2944 {
2945 _zmap_drawlayer_ohead(dest, x, y, layers[1], antiflags, basescr->layeropacity[1-1]!=255, HL_LAYER(1));
2946 _zmap_drawlayer_ohead(dest, x, y, layers[2], antiflags, basescr->layeropacity[2-1]!=255, HL_LAYER(2));
2947 }
2948 _zmap_drawlayer(dest, x, y, layers[5], antiflags, basescr->layeropacity[5-1]!=255, true, HL_LAYER(5));
2949 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 5);
2950
2951 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, -1);
2952
2953 _zmap_drawlayer(dest, x, y, layers[6], antiflags, basescr->layeropacity[6-1]!=255, true, HL_LAYER(6));
2954 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 6);
2955 _zmap_draw_ffc_layer(dest, x, y, flags, basescr, 7);
2956
2957 int num_ffcs = basescr->numFFC();
2958 for(int32_t i=num_ffcs-1; i>=0; i--) // changer ffcs
2959 if(basescr->ffcs[i].data)
2960 if(basescr->ffcs[i].flags&ffc_changer)
2961 putpixel(dest,(basescr->ffcs[i].x.getInt())+x,(basescr->ffcs[i].y.getInt())+y,vc(zc_oldrand()%16));
2962
2963 if(flags&cWALK)
2964 {
2965 if(layers[0])
2966 for(int32_t i=0; i<176; i++)
2967 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[0]->data[i], 0);
2968
2969 for(int32_t k=0; k<2; k++)
2970 {
2971 if(layers[k+1])
2972 for(int32_t i=0; i<176; i++)
2973 put_walkflags(dest,((i&15)<<4)+x,(i&0xF0)+y,layers[k+1]->data[i], 0);
2974 }
2975 for(int32_t i=num_ffcs-1; i>=0; i--)
2976 {
2977 if(auto data = basescr->ffcs[i].data)
2978 {
2979 if(!(basescr->ffcs[i].flags&ffc_changer))
2980 {
2981 newcombo const& cmb = combobuf[data];
2982 int32_t tx=(basescr->ffcs[i].x.getInt())+x;
2983 int32_t ty=(basescr->ffcs[i].y.getInt())+y;
2984
2985 if(basescr->ffcs[i].flags&ffc_solid)
2986 {
2987 rectfill(dest, tx, ty, tx + basescr->ffEffectWidth(i) - 1, ty + basescr->ffEffectHeight(i) - 1, COLOR_SOLID);
2988 }
2989
2990 if(cmb.type == cSLOPE)
2991 {
2992 slope_info s(cmb, tx, ty);
2993 s.draw(dest, 0, 0, COLOR_SLOPE);
2994 }
2995 }
2996 }
2997 }
2998 }
2999
3000 if(flags&cFLAGS)
3001 {
3002 if(LayerMaskInt[CurrentLayer]!=0)
3003 {
3004 for(int32_t i=0; i<176; i++)
3005 {
3006 if(CurrentLayer==0)
3007 {
3008 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,basescr->data[i],basescr->cset[i],flags,basescr->sflag[i]);
3009 }
3010 else
3011 {
3012 if(prv_mode)
3013 {
3014 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,prvlayers[CurrentLayer-1].data[i],prvlayers[CurrentLayer-1].cset[i],flags,prvlayers[CurrentLayer-1].sflag[i]);
3015 }
3016 else if(basescr->layermap[CurrentLayer-1] > 0)
3017 {
3018 int32_t _lscr=(basescr->layermap[CurrentLayer-1]-1)*MAPSCRS+basescr->layerscreen[CurrentLayer-1];
3019
3020 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3021 {
3022 put_flags(dest,((i&15)<<4)+x,(i&0xF0)+y,
3023 TheMaps[_lscr].data[i],
3024 TheMaps[_lscr].cset[i], flags,
3025 TheMaps[_lscr].sflag[i]);
3026 }
3027 }
3028 }
3029 }
3030 }
3031 }
3032
3033 int32_t dark = basescr->flags&cDARK;
3034
3035 if(dark && !(flags&cNODARK)
3036 && !((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM)))
3037 {
3038 for(int32_t j=0; j<80; j++)
3039 {
3040 for(int32_t i=0; i<(80)-j; i++)
3041 {
3042 if(((i^j)&1)==0)
3043 {
3044 putpixel(dest,x+i,y+j,vc(blackout_color));
3045 }
3046 }
3047 }
3048 }
3049
3050 if(ShowMisalignments)
3051 {
3052 check_alignments(dest,x,y,screen);
3053 }
3054 }
3055
3056 void zmap::drawrow(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3057 {
3058 if(map<0)
3059 map=cursor.map;
3060
3061 if(scr<0)
3062 scr=cursor.screen;
3063
3064 mapscr* layer=AbsoluteScr(map,scr);
3065 int32_t layermap=0, layerscreen=0;
3066
3067 if(!(layer->valid&mVALID))
3068 {
3069 // rectfill(dest,x,y,x+255,y+15,dvc(0+1));
3070 rectfill(dest,x,y,x+255,y+15,vc(1));
3071 return;
3072 }
3073
3074 int32_t dark = layer->flags&4;
3075
3076 if(LayerMaskInt[0]==0)
3077 {
3078 rectfill(dest,x,y,x+255,y+15,0);
3079 }
3080
3081 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3082 int order[2] = {2,1};
3083 if (olddraw) zc_swap(order[0],order[1]);
3084 for(int k : order)
3085 {
3086 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3087 {
3088 layermap=layer->layermap[k]-1;
3089
3090 if(layermap>-1 && layermap<map_count)
3091 {
3092 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3093
3094 for(int32_t i=c; i<(c&0xF0)+16; i++)
3095 {
3096 auto data = TheMaps[layerscreen].data[i];
3097 auto cs = TheMaps[layerscreen].cset[i];
3098 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3099 }
3100 }
3101 }
3102 }
3103
3104 if(LayerMaskInt[0]!=0)
3105 {
3106 for(int32_t i=c; i<(c&0xF0)+16; i++)
3107 {
3108 word cmbdat = (i < 176 ? layer->data[i] : 0);
3109 byte cmbcset = (i < 176 ? layer->cset[i] : 0);
3110 int32_t cmbflag = (i < 176 ? layer->sflag[i] : 0);
3111 drawcombo(dest,((i&15)<<4)+x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),
3112 cmbflag,!olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3113 }
3114 }
3115
3116 for(int32_t k=0; k<2; k++)
3117 {
3118 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3119 {
3120 layermap=layer->layermap[k]-1;
3121
3122 if(layermap>-1 && layermap<map_count)
3123 {
3124 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3125
3126 for(int32_t i=c; i<(c&0xF0)+16; i++)
3127 {
3128 auto data = TheMaps[layerscreen].data[i];
3129 auto cs = TheMaps[layerscreen].cset[i];
3130 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3131 }
3132 }
3133 }
3134 }
3135
3136 int32_t doortype[4];
3137
3138 for(int32_t i=0; i<4; i++)
3139 {
3140 switch(layer->door[i])
3141 {
3142 case dOPEN:
3143 doortype[i]=dt_pass;
3144 break;
3145
3146 case dLOCKED:
3147 doortype[i]=dt_lock;
3148 break;
3149
3150 case d1WAYSHUTTER:
3151 case dSHUTTER:
3152 doortype[i]=dt_shut;
3153 break;
3154
3155 case dBOSS:
3156 doortype[i]=dt_boss;
3157 break;
3158
3159 case dBOMB:
3160 doortype[i]=dt_bomb;
3161 break;
3162 }
3163 }
3164
3165 if(c<16)
3166 {
3167 switch(layer->door[up])
3168 {
3169 case dBOMB:
3170 case dOPEN:
3171 case dLOCKED:
3172 case d1WAYSHUTTER:
3173 case dSHUTTER:
3174 case dBOSS:
3175 put_door(dest,7,up,doortype[up],x,y+176,true,scr);
3176 break;
3177 }
3178 }
3179 else if(c>159)
3180 {
3181 switch(layer->door[down])
3182 {
3183 case dBOMB:
3184 case dOPEN:
3185 case dLOCKED:
3186 case d1WAYSHUTTER:
3187 case dSHUTTER:
3188 case dBOSS:
3189 put_door(dest,151,down,doortype[down],x,y-16,true,scr);
3190 break;
3191 }
3192 }
3193
3194 for(int32_t k=2; k<4; k++)
3195 {
3196 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3197 {
3198 layermap=layer->layermap[k]-1;
3199
3200 if(layermap>-1 && layermap<map_count)
3201 {
3202 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3203
3204 for(int32_t i=c; i<(c&0xF0)+16; i++)
3205 {
3206 if(layer->layeropacity[k]<255)
3207 {
3208 overcombotranslucent(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i],layer->layeropacity[k]);
3209 }
3210 else
3211 {
3212 overcombo(dest,((i&15)<<4)+x,y,TheMaps[layerscreen].data[i],TheMaps[layerscreen].cset[i]);
3213 }
3214 }
3215 }
3216 }
3217 }
3218
3219 //Overhead L0
3220 if(LayerMaskInt[0]!=0)
3221 {
3222 for(int32_t i=c; i<(c&0xF0)+16; i++)
3223 {
3224 int32_t ct1=layer->data[i];
3225 int32_t ct3=combobuf[ct1].type;
3226
3227 if(combo_class_buf[ct3].overhead)
3228 {
3229 drawcombo(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],0,0);
3230 }
3231 }
3232 }
3233
3234 //Overhead L1/2
3235 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3236 {
3237 for(int32_t k = 0; k < 2; ++k)
3238 {
3239 if(LayerMaskInt[k+1]!=0)
3240 {
3241 layermap=layer->layermap[k]-1;
3242
3243 if(layermap>-1 && layermap<map_count)
3244 {
3245 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3246 for(int32_t i=c; i<(c&0xF0)+16; i++)
3247 {
3248 auto data = TheMaps[layerscreen].data[i];
3249 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3250 auto cs = TheMaps[layerscreen].cset[i];
3251 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3252 }
3253 }
3254 }
3255 }
3256 }
3257
3258 for(int32_t k=4; k<6; k++)
3259 {
3260 if(LayerMaskInt[k+1]!=0)
3261 {
3262 layermap=layer->layermap[k]-1;
3263
3264 if(layermap>-1 && layermap<map_count)
3265 {
3266 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3267
3268 for(int32_t i=c; i<(c&0xF0)+16; i++)
3269 {
3270 auto data = TheMaps[layerscreen].data[i];
3271 auto cs = TheMaps[layerscreen].cset[i];
3272 drawcombo(dest,((i&15)<<4)+x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3273 }
3274 }
3275 }
3276 }
3277
3278 if(flags&cWALK)
3279 {
3280 if(LayerMaskInt[0]!=0)
3281 {
3282 for(int32_t i=c; i<(c&0xF0)+16; i++)
3283 {
3284 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, -1, map,scr);
3285 }
3286 }
3287
3288 for(int32_t k=0; k<2; k++)
3289 {
3290 if(LayerMaskInt[k+1]!=0)
3291 {
3292 for(int32_t i=c; i<(c&0xF0)+16; i++)
3293 {
3294 put_walkflags_layered_external(dest,((i&15)<<4)+x,y,i, k, map,scr);
3295 }
3296 }
3297 }
3298 }
3299
3300 if(flags&cFLAGS)
3301 {
3302 if(LayerMaskInt[CurrentLayer]!=0)
3303 {
3304 for(int32_t i=c; i<(c&0xF0)+16; i++)
3305 {
3306 if(CurrentLayer==0)
3307 {
3308 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3309 }
3310 else
3311 {
3312 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3313
3314 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3315 {
3316 if(i < 176)
3317 {
3318 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,
3319 TheMaps[_lscr].data[i],
3320 TheMaps[_lscr].cset[i], flags|dark,
3321 TheMaps[_lscr].sflag[i]);
3322 }
3323 else
3324 {
3325 put_flags(dest,((i&15)<<4)+x,/*(i&0xF0)+*/y,0,0, flags|dark,0);
3326 }
3327 }
3328 }
3329 }
3330 }
3331
3332 /*
3333 if (LayerMaskInt[0]!=0) {
3334 for(int32_t i=c; i<(c&0xF0)+16; i++) {
3335 put_flags(dest,((i&15)<<4)+x,y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3336 }
3337 }
3338 */
3339 }
3340
3341 if(ShowMisalignments)
3342 {
3343 if(c<16)
3344 {
3345 check_alignments(dest,x,y,scr);
3346 }
3347 else if(c>159)
3348 {
3349 check_alignments(dest,x,y-160,scr);
3350 }
3351 }
3352 }
3353
3354 void zmap::drawcolumn(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3355 {
3356 if(map<0)
3357 map=cursor.map;
3358
3359 if(scr<0)
3360 scr=cursor.screen;
3361
3362 mapscr* layer=AbsoluteScr(map,scr);
3363 int32_t layermap=0, layerscreen=0;
3364
3365 if(!(layer->valid&mVALID))
3366 {
3367 // rectfill(dest,x,y,x+15,y+175,dvc(0+1));
3368 rectfill(dest,x,y,x+15,y+175,vc(1));
3369 return;
3370 }
3371
3372 int32_t dark = layer->flags&4;
3373
3374 if(LayerMaskInt[0]==0)
3375 {
3376 rectfill(dest,x,y,x+15,y+175,0);
3377 }
3378
3379 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3380 int order[2] = {2,1};
3381 if (olddraw) zc_swap(order[0],order[1]);
3382 for(int k : order)
3383 {
3384 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3385 {
3386 layermap=layer->layermap[k]-1;
3387
3388 if(layermap>-1 && layermap<map_count)
3389 {
3390 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3391
3392 for(int32_t i=c; i<176; i+=16)
3393 {
3394 auto data = TheMaps[layerscreen].data[i];
3395 auto cs = TheMaps[layerscreen].cset[i];
3396 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3397 }
3398 }
3399 }
3400 }
3401
3402 if(LayerMaskInt[0]!=0)
3403 {
3404 for(int32_t i=c; i<176; i+=16)
3405 {
3406 word cmbdat = layer->data[i];
3407 byte cmbcset = layer->cset[i];
3408 int32_t cmbflag = layer->sflag[i];
3409 drawcombo(dest,x,(i&0xF0)+y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3410 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3411 }
3412 }
3413
3414 for(int32_t k=0; k<2; k++)
3415 {
3416 if(LayerMaskInt[k+1]!=0 && !(k==1 && layer->flags7&fLAYER2BG))
3417 {
3418 layermap=layer->layermap[k]-1;
3419
3420 if(layermap>-1 && layermap<map_count)
3421 {
3422 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3423
3424 for(int32_t i=c; i<176; i+=16)
3425 {
3426 auto data = TheMaps[layerscreen].data[i];
3427 auto cs = TheMaps[layerscreen].cset[i];
3428 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3429 }
3430 }
3431 }
3432 }
3433
3434 int32_t doortype[4];
3435
3436 for(int32_t i=0; i<4; i++)
3437 {
3438 switch(layer->door[i])
3439 {
3440 case dOPEN:
3441 doortype[i]=dt_pass;
3442 break;
3443
3444 case dLOCKED:
3445 doortype[i]=dt_lock;
3446 break;
3447
3448 case d1WAYSHUTTER:
3449 case dSHUTTER:
3450 doortype[i]=dt_shut;
3451 break;
3452
3453 case dBOSS:
3454 doortype[i]=dt_boss;
3455 break;
3456
3457 case dBOMB:
3458 doortype[i]=dt_bomb;
3459 break;
3460 }
3461 }
3462
3463 if((c&0x0F)==0)
3464 {
3465 switch(layer->door[left])
3466 {
3467
3468 case dBOMB:
3469 case dOPEN:
3470 case dLOCKED:
3471 case d1WAYSHUTTER:
3472 case dSHUTTER:
3473 case dBOSS:
3474 // put_door(dest,64,left,doortype[left],x+256,y,true);
3475 put_door(dest,64,left,doortype[left],x,y,true,scr);
3476 break;
3477 }
3478 }
3479 else if((c&0x0F)==15)
3480 {
3481 switch(layer->door[right])
3482 {
3483 case dBOMB:
3484 case dOPEN:
3485 case dLOCKED:
3486 case d1WAYSHUTTER:
3487 case dSHUTTER:
3488 case dBOSS:
3489 put_door(dest,78,right,doortype[right],x-16,y,true,scr);
3490 break;
3491 }
3492 }
3493
3494 for(int32_t k=2; k<4; k++)
3495 {
3496 if(LayerMaskInt[k+1]!=0 && !(k==2 && layer->flags7&fLAYER3BG))
3497 {
3498 layermap=layer->layermap[k]-1;
3499
3500 if(layermap>-1 && layermap<map_count)
3501 {
3502 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3503
3504 for(int32_t i=c; i<176; i+=16)
3505 {
3506 auto data = TheMaps[layerscreen].data[i];
3507 auto cs = TheMaps[layerscreen].cset[i];
3508 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3509 }
3510 }
3511 }
3512 }
3513
3514 //Overhead L0
3515 if(LayerMaskInt[0]!=0)
3516 {
3517 for(int32_t i=c; i<176; i+=16)
3518 {
3519 auto data = TheMaps[layerscreen].data[i];
3520 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3521 auto cs = TheMaps[layerscreen].cset[i];
3522 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0);
3523 }
3524 }
3525 //Overhead L1/2
3526 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3527 {
3528 for(int32_t k = 0; k < 2; ++k)
3529 {
3530 if(LayerMaskInt[k+1]!=0)
3531 {
3532 layermap=layer->layermap[k]-1;
3533
3534 if(layermap>-1 && layermap<map_count)
3535 {
3536 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3537 for(int32_t i=c; i<176; i+=16)
3538 {
3539 auto data = TheMaps[layerscreen].data[i];
3540 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3541 auto cs = TheMaps[layerscreen].cset[i];
3542 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3543 }
3544 }
3545 }
3546 }
3547 }
3548
3549
3550 for(int32_t k=4; k<6; k++)
3551 {
3552 if(LayerMaskInt[k+1]!=0)
3553 {
3554 layermap=layer->layermap[k]-1;
3555
3556 if(layermap>-1 && layermap<map_count)
3557 {
3558 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3559
3560 for(int32_t i=c; i<176; i+=16)
3561 {
3562 auto data = TheMaps[layerscreen].data[i];
3563 auto cs = TheMaps[layerscreen].cset[i];
3564 drawcombo(dest,x,(i&0xF0)+y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3565 }
3566 }
3567 }
3568 }
3569
3570 if(flags&cWALK)
3571 {
3572 if(LayerMaskInt[0]!=0)
3573 {
3574 for(int32_t i=c&0xF; i<176; i+=16)
3575 {
3576 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, -1, map,scr);
3577 }
3578 }
3579
3580 for(int32_t k=0; k<2; k++)
3581 {
3582 if(LayerMaskInt[k+1]!=0)
3583 {
3584 for(int32_t i=c&0xF; i<176; i+=16)
3585 {
3586 put_walkflags_layered_external(dest,x,y+(i&0xF0),i, k, map,scr);
3587 }
3588 }
3589 }
3590 }
3591
3592 if(flags&cFLAGS)
3593 {
3594 if(LayerMaskInt[CurrentLayer]!=0)
3595 {
3596 for(int32_t i=c; i<176; i+=16)
3597 {
3598 if(CurrentLayer==0)
3599 {
3600 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3601 }
3602 else
3603 {
3604 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3605
3606 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3607 {
3608 put_flags(dest,/*((i&15)<<4)+*/x,(i&0xF0)+y,
3609 TheMaps[_lscr].data[i],
3610 TheMaps[_lscr].cset[i], flags|dark,
3611 TheMaps[_lscr].sflag[i]);
3612 }
3613 }
3614 }
3615 }
3616 }
3617
3618 if(ShowMisalignments)
3619 {
3620 if((c&0x0F)==0)
3621 {
3622 check_alignments(dest,x,y,scr);
3623 }
3624 else if((c&0x0F)==15)
3625 {
3626 check_alignments(dest,x-240,y,scr);
3627 }
3628 }
3629 }
3630
3631 void zmap::drawblock(BITMAP* dest,int32_t x,int32_t y,int32_t flags,int32_t c,int32_t map,int32_t scr)
3632 {
3633 if(map<0)
3634 map=cursor.map;
3635
3636 if(scr<0)
3637 scr=cursor.screen;
3638
3639 mapscr* layer=AbsoluteScr(map,scr);
3640 int32_t layermap=0, layerscreen=0;
3641
3642 if(!(layer->valid&mVALID))
3643 {
3644 // rectfill(dest,x,y,x+15,y+15,dvc(0+1));
3645 rectfill(dest,x,y,x+15,y+15,vc(1));
3646 return;
3647 }
3648
3649 int32_t dark = layer->flags&4;
3650
3651 if(LayerMaskInt[0]!=0)
3652 {
3653 rectfill(dest,x,y,x+15,y+15,0);
3654 }
3655
3656 bool olddraw = get_qr(qr_CLASSIC_DRAWING_ORDER);
3657 int order[2] = {2,1};
3658 if (olddraw) zc_swap(order[0],order[1]);
3659 for(int k : order)
3660 {
3661 if(LayerMaskInt[k+1]!=0 && (k==1)?(layer->flags7&fLAYER2BG):(layer->flags7&fLAYER3BG))
3662 {
3663 layermap=layer->layermap[k]-1;
3664
3665 if(layermap>-1 && layermap<map_count)
3666 {
3667 layerscreen=layermap*MAPSCRS+layer->layerscreen[2-1];
3668
3669 auto data = TheMaps[layerscreen].data[c];
3670 auto cs = TheMaps[layerscreen].cset[c];
3671 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3672 }
3673 }
3674 }
3675
3676 if(LayerMaskInt[0]!=0)
3677 {
3678 word cmbdat = layer->data[c];
3679 byte cmbcset = layer->cset[c];
3680 int32_t cmbflag = layer->sflag[c];
3681 drawcombo(dest,x,y,cmbdat,cmbcset,((flags|dark)&~cWALK),cmbflag,
3682 !olddraw || (layer->flags7&fLAYER3BG||layer->flags7&fLAYER2BG));
3683 }
3684
3685
3686 for(int32_t k=0; k<2; k++)
3687 {
3688 if(LayerMaskInt[k+1]!=0)
3689 {
3690 layermap=layer->layermap[k]-1;
3691
3692 if(layermap>-1 && layermap<map_count)
3693 {
3694 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3695
3696 auto data = TheMaps[layerscreen].data[c];
3697 auto cs = TheMaps[layerscreen].cset[c];
3698 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3699 }
3700 }
3701 }
3702
3703 for(int32_t k=2; k<4; k++)
3704 {
3705 if(LayerMaskInt[k+1]!=0)
3706 {
3707 layermap=layer->layermap[k]-1;
3708
3709 if(layermap>-1 && layermap<map_count)
3710 {
3711 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3712 auto data = TheMaps[layerscreen].data[c];
3713 auto cs = TheMaps[layerscreen].cset[c];
3714 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3715 }
3716 }
3717 }
3718
3719 //Overhead L0
3720 if(LayerMaskInt[0]!=0)
3721 {
3722 auto data = TheMaps[layerscreen].data[c];
3723 if(combo_class_buf[combobuf[data].type].overhead)
3724 {
3725 auto cs = TheMaps[layerscreen].cset[c];
3726 drawcombo(dest,x,y,data,cs,0,0);
3727 }
3728 }
3729 //Overhead L1/2
3730 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3731 {
3732 for(int32_t k = 0; k < 2; ++k)
3733 {
3734 if(LayerMaskInt[k+1]!=0)
3735 {
3736 layermap=layer->layermap[k]-1;
3737
3738 if(layermap>-1 && layermap<map_count)
3739 {
3740 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3741 auto data = TheMaps[layerscreen].data[c];
3742 if(!combo_class_buf[combobuf[data].type].overhead) continue;
3743 auto cs = TheMaps[layerscreen].cset[c];
3744 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3745 }
3746 }
3747 }
3748 }
3749
3750
3751 for(int32_t k=4; k<6; k++)
3752 {
3753 if(LayerMaskInt[k+1]!=0)
3754 {
3755 layermap=layer->layermap[k]-1;
3756
3757 if(layermap>-1 && layermap<map_count)
3758 {
3759 layerscreen=layermap*MAPSCRS+layer->layerscreen[k];
3760 auto data = TheMaps[layerscreen].data[c];
3761 auto cs = TheMaps[layerscreen].cset[c];
3762 drawcombo(dest,x,y,data,cs,0,0,true,layer->layeropacity[k]!=255);
3763 }
3764 }
3765 }
3766
3767 if(flags&cWALK)
3768 {
3769 if(LayerMaskInt[0]!=0)
3770 {
3771 put_walkflags_layered_external(dest,x,y,c,-1, map,scr);
3772 }
3773
3774 for(int32_t k=0; k<2; k++)
3775 {
3776 if(LayerMaskInt[k+1]!=0)
3777 {
3778 put_walkflags_layered_external(dest,x,y,c,k, map,scr);
3779 }
3780 }
3781 }
3782
3783 if(flags&cFLAGS)
3784 {
3785 if(LayerMaskInt[CurrentLayer]!=0)
3786 {
3787 int32_t i = c;
3788 //for(int32_t i=c; i==c; i++)
3789 {
3790 if(CurrentLayer==0)
3791 {
3792 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,layer->data[i],layer->cset[i],flags|dark,layer->sflag[i]);
3793 }
3794 else
3795 {
3796 int32_t _lscr=(layer->layermap[CurrentLayer-1]-1)*MAPSCRS+layer->layerscreen[CurrentLayer-1];
3797
3798 if(_lscr>-1 && _lscr<map_count*MAPSCRS)
3799 {
3800 put_flags(dest,/*((i&15)<<4)+*/x,/*(i&0xF0)+*/y,
3801 TheMaps[_lscr].data[i],
3802 TheMaps[_lscr].cset[i], flags|dark,
3803 TheMaps[_lscr].sflag[i]);
3804 }
3805 }
3806 }
3807 }
3808 }
3809
3810 if(ShowMisalignments)
3811 {
3812 switch(c)
3813 {
3814 case 0:
3815 check_alignments(dest,x,y,scr);
3816 break;
3817
3818 case 15:
3819 check_alignments(dest,x-240,y,scr);
3820 break;
3821
3822 case 160:
3823 check_alignments(dest,x,y-160,scr);
3824 break;
3825
3826 case 175:
3827 check_alignments(dest,x-240,y-160,scr);
3828 break;
3829 }
3830 }
3831 }
3832
3833 void zmap::drawstaticblock(BITMAP* dest,int32_t x,int32_t y)
3834 {
3835 if (InvalidBG == 2)
3836 {
3837 draw_checkerboard(dest, x, y, 16);
3838 }
3839 else if(InvalidBG == 1)
3840 {
3841 for(int32_t dy=0; dy<16; dy++)
3842 {
3843 for(int32_t dx=0; dx<16; dx++)
3844 {
3845 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3846 }
3847 }
3848 }
3849 else
3850 {
3851 rectfill(dest, x, y, x+15, y+15, vc(0));
3852 rect(dest, x, y, x+15, y+15, vc(15));
3853 line(dest, x, y, x+15, y+15, vc(15));
3854 line(dest, x, y+15, x+15, y, vc(15));
3855 }
3856 }
3857
3858 void zmap::drawstaticcolumn(BITMAP* dest,int32_t x,int32_t y)
3859 {
3860 if (InvalidBG == 2)
3861 {
3862 for(int32_t q = 0; q < 11; ++q)
3863 draw_checkerboard(dest, x, y + q * 16, 16);
3864 }
3865 else if(InvalidBG == 1)
3866 {
3867 for(int32_t dy=0; dy<176; dy++)
3868 {
3869 for(int32_t dx=0; dx<16; dx++)
3870 {
3871 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3872 }
3873 }
3874 }
3875 else
3876 {
3877 rectfill(dest, x, y, x+15, y+175, vc(0));
3878 rect(dest, x, y, x+15, y+175, vc(15));
3879 line(dest, x, y, x+15, y+175, vc(15));
3880 line(dest, x, y+175, x+15, y, vc(15));
3881 }
3882 }
3883
3884 void zmap::drawstaticrow(BITMAP* dest,int32_t x,int32_t y)
3885 {
3886 if (InvalidBG == 2)
3887 {
3888 for (int32_t q = 0; q < 16; ++q)
3889 draw_checkerboard(dest, x + q * 16, y, 16);
3890 }
3891 else if(InvalidBG == 1)
3892 {
3893 for(int32_t dy=0; dy<16; dy++)
3894 {
3895 for(int32_t dx=0; dx<256; dx++)
3896 {
3897 dest->line[y+dy][x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
3898 }
3899 }
3900 }
3901 else
3902 {
3903 rectfill(dest, x, y, x+255, y+15, vc(0));
3904 rect(dest, x, y, x+255, y+15, vc(15));
3905 line(dest, x, y, x+255, y+15, vc(15));
3906 line(dest, x, y+15, x+255, y, vc(15));
3907 }
3908 }
3909
3910 void zmap::draw_template(BITMAP* dest,int32_t x,int32_t y)
3911 {
3912 for(int32_t i=0; i<176; i++)
3913 {
3914 word cmbdat = screens[TEMPLATE].data[i];
3915 byte cmbcset = screens[TEMPLATE].cset[i];
3916 int32_t cmbflag = screens[TEMPLATE].sflag[i];
3917 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3918 }
3919 }
3920
3921 void zmap::draw_template2(BITMAP* dest,int32_t x,int32_t y)
3922 {
3923 for(int32_t i=0; i<176; i++)
3924 {
3925 word cmbdat = screens[TEMPLATE2].data[i];
3926 byte cmbcset = screens[TEMPLATE2].cset[i];
3927 int32_t cmbflag = screens[TEMPLATE2].sflag[i];
3928 put_combo(dest,((i&15)<<4)+x,(i&0xF0)+y,cmbdat,cmbcset,0,cmbflag);
3929 }
3930 }
3931
3932 void zmap::draw_secret(BITMAP *dest, int32_t pos)
3933 {
3934 word cmbdat = screens[TEMPLATE].data[pos];
3935 byte cmbcset = screens[TEMPLATE].cset[pos];
3936 int32_t cmbflag = screens[TEMPLATE].sflag[pos];
3937 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3938 }
3939
3940 void zmap::draw_secret2(BITMAP *dest, int32_t scombo)
3941 {
3942 word cmbdat = screens[cursor.screen].secretcombo[scombo];
3943 byte cmbcset = screens[cursor.screen].secretcset[scombo];
3944 byte cmbflag = screens[cursor.screen].secretflag[scombo];
3945 put_combo(dest,0,0,cmbdat,cmbcset,0,cmbflag);
3946 }
3947
3948 void zmap::scroll(int32_t dir, bool warp)
3949 {
3950 if(cursor.map<map_count)
3951 {
3952 switch(dir)
3953 {
3954 case up:
3955 if(warp && Map.CurrScr()->flags2&wfUP)
3956 {
3957 dowarp(1,Map.CurrScr()->sidewarpindex&3);
3958 }
3959 else if(cursor.screen>15)
3960 {
3961 setCurrScr(cursor.screen - 16);
3962 }
3963
3964 break;
3965
3966 case down:
3967 if(warp && Map.CurrScr()->flags2&wfDOWN)
3968 {
3969 dowarp(1,(Map.CurrScr()->sidewarpindex>>2)&3);
3970 }
3971 else if(cursor.screen<MAPSCRS-16)
3972 {
3973 setCurrScr(cursor.screen + 16);
3974 }
3975
3976 break;
3977
3978 case left:
3979 if(warp && Map.CurrScr()->flags2&wfLEFT)
3980 {
3981 dowarp(1,(Map.CurrScr()->sidewarpindex>>4)&3);
3982 }
3983 else if(cursor.screen&15)
3984 {
3985 setCurrScr(cursor.screen - 1);
3986 }
3987
3988 break;
3989
3990 case right:
3991 if(warp && Map.CurrScr()->flags2&wfRIGHT)
3992 {
3993 dowarp(1,(Map.CurrScr()->sidewarpindex>>6)&3);
3994 }
3995 else if((cursor.screen&15)<15 && cursor.screen<MAPSCRS-1)
3996 {
3997 setCurrScr(cursor.screen + 1);
3998 }
3999
4000 break;
4001 }
4002 }
4003 }
4004
4005 void fetch_door(int side, int door, int dcs, word data[176], byte cset[176])
4006 {
4007 switch(side)
4008 {
4009 case up:
4010 switch(door)
4011 {
4012 case dWALL:
4013 case dBOMB:
4014 case dWALK:
4015 data[7] = DoorComboSets[dcs].doorcombo_u[dt_wall][0];
4016 cset[7] = DoorComboSets[dcs].doorcset_u[dt_wall][0];
4017 data[8] = DoorComboSets[dcs].doorcombo_u[dt_wall][1];
4018 cset[8] = DoorComboSets[dcs].doorcset_u[dt_wall][1];
4019 data[23] = DoorComboSets[dcs].doorcombo_u[dt_wall][2];
4020 cset[23] = DoorComboSets[dcs].doorcset_u[dt_wall][2];
4021 data[24] = DoorComboSets[dcs].doorcombo_u[dt_wall][3];
4022 cset[24] = DoorComboSets[dcs].doorcset_u[dt_wall][3];
4023 break;
4024
4025 default:
4026 data[7] = DoorComboSets[dcs].doorcombo_u[dt_pass][0];
4027 cset[7] = DoorComboSets[dcs].doorcset_u[dt_pass][0];
4028 data[8] = DoorComboSets[dcs].doorcombo_u[dt_pass][1];
4029 cset[8] = DoorComboSets[dcs].doorcset_u[dt_pass][1];
4030 data[23] = DoorComboSets[dcs].doorcombo_u[dt_pass][2];
4031 cset[23] = DoorComboSets[dcs].doorcset_u[dt_pass][2];
4032 data[24] = DoorComboSets[dcs].doorcombo_u[dt_pass][3];
4033 cset[24] = DoorComboSets[dcs].doorcset_u[dt_pass][3];
4034 break;
4035 }
4036
4037 break;
4038
4039 case down:
4040 switch(door)
4041 {
4042 case dWALL:
4043 case dBOMB:
4044 case dWALK:
4045 data[151] = DoorComboSets[dcs].doorcombo_d[dt_wall][0];
4046 cset[151] = DoorComboSets[dcs].doorcset_d[dt_wall][0];
4047 data[152] = DoorComboSets[dcs].doorcombo_d[dt_wall][1];
4048 cset[152] = DoorComboSets[dcs].doorcset_d[dt_wall][1];
4049 data[167] = DoorComboSets[dcs].doorcombo_d[dt_wall][2];
4050 cset[167] = DoorComboSets[dcs].doorcset_d[dt_wall][2];
4051 data[168] = DoorComboSets[dcs].doorcombo_d[dt_wall][3];
4052 cset[168] = DoorComboSets[dcs].doorcset_d[dt_wall][3];
4053 break;
4054
4055 default:
4056 data[151] = DoorComboSets[dcs].doorcombo_d[dt_pass][0];
4057 cset[151] = DoorComboSets[dcs].doorcset_d[dt_pass][0];
4058 data[152] = DoorComboSets[dcs].doorcombo_d[dt_pass][1];
4059 cset[152] = DoorComboSets[dcs].doorcset_d[dt_pass][1];
4060 data[167] = DoorComboSets[dcs].doorcombo_d[dt_pass][2];
4061 cset[167] = DoorComboSets[dcs].doorcset_d[dt_pass][2];
4062 data[168] = DoorComboSets[dcs].doorcombo_d[dt_pass][3];
4063 cset[168] = DoorComboSets[dcs].doorcset_d[dt_pass][3];
4064 break;
4065 }
4066
4067 break;
4068
4069 case left:
4070 switch(door)
4071 {
4072 case dWALL:
4073 case dBOMB:
4074 case dWALK:
4075 data[64] = DoorComboSets[dcs].doorcombo_l[dt_wall][0];
4076 cset[64] = DoorComboSets[dcs].doorcset_l[dt_wall][0];
4077 data[65] = DoorComboSets[dcs].doorcombo_l[dt_wall][1];
4078 cset[65] = DoorComboSets[dcs].doorcset_l[dt_wall][1];
4079 data[80] = DoorComboSets[dcs].doorcombo_l[dt_wall][2];
4080 cset[80] = DoorComboSets[dcs].doorcset_l[dt_wall][2];
4081 data[81] = DoorComboSets[dcs].doorcombo_l[dt_wall][3];
4082 cset[81] = DoorComboSets[dcs].doorcset_l[dt_wall][3];
4083 data[96] = DoorComboSets[dcs].doorcombo_l[dt_wall][4];
4084 cset[96] = DoorComboSets[dcs].doorcset_l[dt_wall][4];
4085 data[97] = DoorComboSets[dcs].doorcombo_l[dt_wall][5];
4086 cset[97] = DoorComboSets[dcs].doorcset_l[dt_wall][5];
4087 break;
4088
4089 default:
4090 data[64] = DoorComboSets[dcs].doorcombo_l[dt_pass][0];
4091 cset[64] = DoorComboSets[dcs].doorcset_l[dt_pass][0];
4092 data[65] = DoorComboSets[dcs].doorcombo_l[dt_pass][1];
4093 cset[65] = DoorComboSets[dcs].doorcset_l[dt_pass][1];
4094 data[80] = DoorComboSets[dcs].doorcombo_l[dt_pass][2];
4095 cset[80] = DoorComboSets[dcs].doorcset_l[dt_pass][2];
4096 data[81] = DoorComboSets[dcs].doorcombo_l[dt_pass][3];
4097 cset[81] = DoorComboSets[dcs].doorcset_l[dt_pass][3];
4098 data[96] = DoorComboSets[dcs].doorcombo_l[dt_pass][4];
4099 cset[96] = DoorComboSets[dcs].doorcset_l[dt_pass][4];
4100 data[97] = DoorComboSets[dcs].doorcombo_l[dt_pass][5];
4101 cset[97] = DoorComboSets[dcs].doorcset_l[dt_pass][5];
4102 break;
4103 }
4104
4105 break;
4106
4107 case right:
4108 switch(door)
4109 {
4110 case dWALL:
4111 case dBOMB:
4112 case dWALK:
4113 data[78] = DoorComboSets[dcs].doorcombo_r[dt_wall][0];
4114 cset[78] = DoorComboSets[dcs].doorcset_r[dt_wall][0];
4115 data[79] = DoorComboSets[dcs].doorcombo_r[dt_wall][1];
4116 cset[79] = DoorComboSets[dcs].doorcset_r[dt_wall][1];
4117 data[94] = DoorComboSets[dcs].doorcombo_r[dt_wall][2];
4118 cset[94] = DoorComboSets[dcs].doorcset_r[dt_wall][2];
4119 data[95] = DoorComboSets[dcs].doorcombo_r[dt_wall][3];
4120 cset[95] = DoorComboSets[dcs].doorcset_r[dt_wall][3];
4121 data[110] = DoorComboSets[dcs].doorcombo_r[dt_wall][4];
4122 cset[110] = DoorComboSets[dcs].doorcset_r[dt_wall][4];
4123 data[111] = DoorComboSets[dcs].doorcombo_r[dt_wall][5];
4124 cset[111] = DoorComboSets[dcs].doorcset_r[dt_wall][5];
4125 break;
4126
4127 default:
4128 data[78] = DoorComboSets[dcs].doorcombo_r[dt_pass][0];
4129 cset[78] = DoorComboSets[dcs].doorcset_r[dt_pass][0];
4130 data[79] = DoorComboSets[dcs].doorcombo_r[dt_pass][1];
4131 cset[79] = DoorComboSets[dcs].doorcset_r[dt_pass][1];
4132 data[94] = DoorComboSets[dcs].doorcombo_r[dt_pass][2];
4133 cset[94] = DoorComboSets[dcs].doorcset_r[dt_pass][2];
4134 data[95] = DoorComboSets[dcs].doorcombo_r[dt_pass][3];
4135 cset[95] = DoorComboSets[dcs].doorcset_r[dt_pass][3];
4136 data[110] = DoorComboSets[dcs].doorcombo_r[dt_pass][4];
4137 cset[110] = DoorComboSets[dcs].doorcset_r[dt_pass][4];
4138 data[111] = DoorComboSets[dcs].doorcombo_r[dt_pass][5];
4139 cset[111] = DoorComboSets[dcs].doorcset_r[dt_pass][5];
4140 break;
4141 }
4142
4143 break;
4144 }
4145 }
4146 void zmap::DoPutDoorCommand(int side, int door, bool force)
4147 {
4148 if(!force && screens[cursor.screen].door[side] == door)
4149 return;
4150 bool already_list = InListCommand();
4151 if(!already_list)
4152 StartListCommand();
4153 DoSetDoorCommand(cursor.screen,side,door);
4154 if(door != dNONE)
4155 {
4156 word data[176] = {0};
4157 byte cset[176] = {0};
4158 fetch_door(side, door, screens[cursor.screen].door_combo_set, data, cset);
4159 for(int q = 0; q < 176; ++q)
4160 if(data[q])
4161 DoSetComboCommand(cursor.map,cursor.screen,q,data[q],cset[q]);
4162 }
4163 if(!already_list)
4164 FinishListCommand();
4165 }
4166 void zmap::putdoor(int32_t screen,int32_t side,int32_t door)
4167 {
4168 if(screens[screen].door[side] == door)
4169 return;
4170
4171 screens[screen].door[side] = door;
4172 if(door != dNONE)
4173 {
4174 word data[176] = {0};
4175 byte cset[176] = {0};
4176 fetch_door(side, door, screens[screen].door_combo_set, data, cset);
4177 for(int q = 0; q < 176; ++q)
4178 if(data[q])
4179 {
4180 screens[screen].data[q] = data[q];
4181 screens[screen].cset[q] = cset[q];
4182 }
4183 }
4184 }
4185
4186 void list_command::execute()
4187 {
4188 for (auto command : commands)
4189 {
4190 command->execute();
4191 }
4192 }
4193
4194 void list_command::undo()
4195 {
4196 for (int i = commands.size() - 1; i >= 0; i--)
4197 {
4198 commands[i]->undo();
4199 }
4200 }
4201
4202 int list_command::size()
4203 {
4204 int s = 0;
4205 for (auto command : commands)
4206 {
4207 s += command->size();
4208 }
4209 return s;
4210 }
4211
4212 void set_combo_command::execute()
4213 {
4214 mapscr* scr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4215 if (!scr_ptr) return;
4216
4217 if (combo != -1) scr_ptr->data[pos] = combo;
4218 scr_ptr->cset[pos] = cset;
4219 }
4220
4221 void set_combo_command::undo()
4222 {
4223 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4224 if(!mapscr_ptr) return;
4225 if (combo != -1) mapscr_ptr->data[pos] = prev_combo;
4226 mapscr_ptr->cset[pos] = prev_cset;
4227 }
4228
4229 set_ffc_command::data_t set_ffc_command::create_data(const ffcdata& ffc)
4230 {
4231 std::array<int, 8> initd_arr;
4232 std::copy(std::begin(ffc.initd), std::end(ffc.initd), initd_arr.begin());
4233
4234 return {
4235 .x = ffc.x,
4236 .y = ffc.y,
4237 .vx = ffc.vx,
4238 .vy = ffc.vy,
4239 .ax = ffc.ax,
4240 .ay = ffc.ay,
4241 .data = ffc.data,
4242 .cset = ffc.cset,
4243 .delay = ffc.delay,
4244 .link = ffc.link,
4245 .script = ffc.script,
4246 .tw = ffc.txsz,
4247 .th = ffc.tysz,
4248 .ew = ffc.hit_width,
4249 .eh = ffc.hit_height,
4250 .flags = ffc.flags,
4251 .initd = initd_arr,
4252 .layer = ffc.layer
4253 };
4254 }
4255
4256 void set_ffc_command::execute()
4257 {
4258 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4259 if(!mapscr_ptr) return;
4260
4261 mapscr_ptr->valid |= mVALID;
4262 mapscr_ptr->ffcs[i].x = data.x;
4263 mapscr_ptr->ffcs[i].y = data.y;
4264 mapscr_ptr->ffcs[i].vx = data.vx;
4265 mapscr_ptr->ffcs[i].vy = data.vy;
4266 mapscr_ptr->ffcs[i].ax = data.ax;
4267 mapscr_ptr->ffcs[i].ay = data.ay;
4268 mapscr_ptr->ffcs[i].data = data.data;
4269 mapscr_ptr->ffcs[i].cset = data.cset;
4270 mapscr_ptr->ffcs[i].delay = data.delay;
4271 mapscr_ptr->ffcs[i].link = data.link;
4272 mapscr_ptr->ffcs[i].script = data.script;
4273 mapscr_ptr->ffcs[i].flags = data.flags;
4274 mapscr_ptr->ffEffectWidth(i, data.ew);
4275 mapscr_ptr->ffEffectHeight(i, data.eh);
4276 mapscr_ptr->ffTileWidth(i, data.tw);
4277 mapscr_ptr->ffTileHeight(i, data.th);
4278 std::copy(std::begin(data.initd), std::end(data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4279 mapscr_ptr->ffcs[i].layer = data.layer;
4280 mapscr_ptr->ffcCountMarkDirty();
4281 mapscr_ptr->ffcs[i].updateSolid();
4282 }
4283
4284 void set_ffc_command::undo()
4285 {
4286 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4287 if(!mapscr_ptr) return;
4288
4289 mapscr_ptr->ffcs[i].x = prev_data.x;
4290 mapscr_ptr->ffcs[i].y = prev_data.y;
4291 mapscr_ptr->ffcs[i].vx = prev_data.vx;
4292 mapscr_ptr->ffcs[i].vy = prev_data.vy;
4293 mapscr_ptr->ffcs[i].ax = prev_data.ax;
4294 mapscr_ptr->ffcs[i].ay = prev_data.ay;
4295 mapscr_ptr->ffcs[i].data = prev_data.data;
4296 mapscr_ptr->ffcs[i].cset = prev_data.cset;
4297 mapscr_ptr->ffcs[i].delay = prev_data.delay;
4298 mapscr_ptr->ffcs[i].link = prev_data.link;
4299 mapscr_ptr->ffcs[i].script = prev_data.script;
4300 mapscr_ptr->ffcs[i].flags = prev_data.flags;
4301 mapscr_ptr->ffEffectWidth(i, prev_data.ew);
4302 mapscr_ptr->ffEffectHeight(i, prev_data.eh);
4303 mapscr_ptr->ffTileWidth(i, prev_data.tw);
4304 mapscr_ptr->ffTileHeight(i, prev_data.th);
4305 std::copy(std::begin(prev_data.initd), std::end(prev_data.initd), std::begin(mapscr_ptr->ffcs[i].initd));
4306 mapscr_ptr->ffcs[i].layer = prev_data.layer;
4307 mapscr_ptr->ffcCountMarkDirty();
4308 mapscr_ptr->ffcs[i].updateSolid();
4309 }
4310
4311 void set_flag_command::execute()
4312 {
4313 mapscr* mapscr_ptr = Map.AbsoluteScrMakeValid(map, scr);
4314 if(!mapscr_ptr) return;
4315
4316 mapscr_ptr->valid |= mVALID;
4317 mapscr_ptr->sflag[pos] = flag;
4318 }
4319
4320 void set_flag_command::undo()
4321 {
4322 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4323 if(!mapscr_ptr) return;
4324 mapscr_ptr->sflag[pos] = prev_flag;
4325 }
4326
4327 void set_door_command::execute()
4328 {
4329 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4330 if(!mapscr_ptr) return;
4331
4332 mapscr_ptr->valid |= mVALID;
4333 mapscr_ptr->door[side] = door;
4334 }
4335
4336 void set_door_command::undo()
4337 {
4338 Map.AbsoluteScr(cursor.map, cursor.screen)->door[side] = prev_door;
4339 }
4340
4341 void set_dcs_command::execute()
4342 {
4343 auto* mapscr_ptr = Map.AbsoluteScrMakeValid(cursor.map, cursor.screen);
4344 if(!mapscr_ptr) return;
4345
4346 mapscr_ptr->valid |= mVALID;
4347 mapscr_ptr->door_combo_set = dcs;
4348 }
4349
4350 void set_dcs_command::undo()
4351 {
4352 Map.AbsoluteScr(cursor.map, cursor.screen)->door_combo_set = prev_dcs;
4353 }
4354
4355 void paste_screen_command::execute()
4356 {
4357 perform(screen.get());
4358 }
4359
4360 void paste_screen_command::undo()
4361 {
4362 if (prev_screens.size() > 1)
4363 {
4364 ASSERT(type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen);
4365 ASSERT(prev_screens.size() == 128);
4366 for (int i = 0; i < 128; i++)
4367 {
4368 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, i), prev_screens[i].get());
4369 // TODO: why not just this?
4370 // If this changes, also change the line in PasteAllToAll and PasteAll to use simply copy assignment.
4371 // *Map.AbsoluteScr(map, i) = *prev_screens[i].get();
4372 }
4373 return;
4374 }
4375
4376 perform(prev_screens[0].get());
4377 }
4378
4379 int paste_screen_command::size()
4380 {
4381 return prev_screens.size() + 1;
4382 }
4383
4384 void paste_screen_command::perform(mapscr* to)
4385 {
4386 if (to)
4387 {
4388 switch (type) {
4389 case ScreenAll: Map.PasteAll(*to, screen_index); break;
4390 case ScreenAllToEveryScreen: Map.PasteAllToAll(*to); break;
4391 case ScreenData: Map.PasteScreenData(*to, screen_index); break;
4392 case ScreenDoors: Map.PasteDoors(*to, screen_index); break;
4393 case ScreenEnemies: Map.PasteEnemies(*to, screen_index); break;
4394 case ScreenFFCombos: Map.PasteFFCombos(*to, screen_index); break;
4395 case ScreenGuy: Map.PasteGuy(*to, screen_index); break;
4396 case ScreenLayers: Map.PasteLayers(*to, screen_index); break;
4397 case ScreenPalette: Map.PastePalette(*to, screen_index); break;
4398 case ScreenPartial: Map.Paste(*to, screen_index); break;
4399 case ScreenPartialToEveryScreen: Map.PasteToAll(*to); break;
4400 case ScreenRoom: Map.PasteRoom(*to, screen_index); break;
4401 case ScreenSecretCombos: Map.PasteSecretCombos(*to, screen_index); break;
4402 case ScreenUnderCombo: Map.PasteUnderCombo(*to, screen_index); break;
4403 case ScreenWarpLocations: Map.PasteWarpLocations(*to, screen_index); break;
4404 case ScreenWarps: Map.PasteWarps(*to, screen_index); break;
4405 }
4406 }
4407 else
4408 {
4409 Map.clearscr(screen_index);
4410 }
4411 refresh(rALL);
4412 }
4413
4414 void set_screen_command::execute()
4415 {
4416 if (screen)
4417 {
4418 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), screen.get());
4419 }
4420 else
4421 {
4422 Map.clearscr(screen_index);
4423 }
4424 refresh(rALL);
4425 }
4426
4427 void set_screen_command::undo()
4428 {
4429 if (prev_screen)
4430 {
4431 copy_mapscr(Map.AbsoluteScrMakeValid(cursor.map, screen_index), prev_screen.get());
4432 }
4433 else
4434 {
4435 Map.clearscr(screen_index);
4436 }
4437 refresh(rALL);
4438 }
4439
4440 int set_screen_command::size()
4441 {
4442 return (prev_screen ? 1 : 0) + (screen ? 1 : 0);
4443 }
4444
4445 static std::shared_ptr<list_command> current_list_command;
4446 void zmap::StartListCommand()
4447 {
4448 ASSERT(!current_list_command);
4449 current_list_command.reset(new list_command);
4450 }
4451
4452 void zmap::FinishListCommand()
4453 {
4454 if (current_list_command->commands.size() == 1)
4455 {
4456 undo_stack.push_back(current_list_command->commands[0]);
4457 }
4458 else if (current_list_command->commands.size() > 1)
4459 {
4460 undo_stack.push_back(current_list_command);
4461 }
4462 CapCommandHistory();
4463 current_list_command = nullptr;
4464 }
4465
4466 void zmap::RevokeListCommand()
4467 {
4468 current_list_command->undo();
4469 current_list_command = nullptr;
4470 }
4471
4472 bool zmap::InListCommand() const
4473 {
4474 return current_list_command ? true : false;
4475 }
4476
4477 void zmap::ExecuteCommand(std::shared_ptr<user_input_command> command, bool skip_execute)
4478 {
4479 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4480 if (!skip_execute) command->execute();
4481 if (current_list_command)
4482 {
4483 current_list_command->commands.push_back(command);
4484 if (current_list_command->commands.size() == 1)
4485 {
4486 current_list_command->cursor = command->cursor;
4487 }
4488 }
4489 else
4490 {
4491 undo_stack.push_back(command);
4492 CapCommandHistory();
4493 }
4494 saved = false;
4495 }
4496
4497 void zmap::UndoCommand()
4498 {
4499 if (undo_stack.size() <= 0) return;
4500
4501 // If not currently looking at the associated screen, first change the view
4502 // and wait for the next call to actually undo this command.
4503 auto command = undo_stack.back();
4504 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4505 {
4506 setCursor(command.get()->cursor);
4507 return;
4508 }
4509
4510 command->undo();
4511 redo_stack.push(command);
4512 undo_stack.pop_back();
4513 saved = false;
4514 }
4515
4516 void zmap::RedoCommand()
4517 {
4518 if (redo_stack.size() <= 0) return;
4519
4520 // If not currently selected the associated screen, first change the cursor
4521 // and wait for the next call to actually execute this command.
4522 auto command = redo_stack.top();
4523 if (command->cursor.map != Map.getCurrMap() || command->cursor.screen != Map.getCurrScr())
4524 {
4525 setCursor(command.get()->cursor);
4526 return;
4527 }
4528
4529 command->execute();
4530 undo_stack.push_back(command);
4531 redo_stack.pop();
4532 saved = false;
4533 }
4534
4535 11 void zmap::ClearCommandHistory()
4536 {
4537 11 current_list_command = nullptr;
4538 11 undo_stack = std::deque<std::shared_ptr<user_input_command>>();
4539 11 redo_stack = std::stack<std::shared_ptr<user_input_command>>();
4540 11 }
4541
4542 // Extra amount is from mapscr's vectors.
4543 static int size_of_mapscr = sizeof(mapscr) + 4*176;
4544 // Allow the undo system to use roughly 100 MB of memory.
4545 // This doesn't count the memory used by commands that don't store a mapscr,
4546 // but that should be negligible.
4547 12 static int max_command_size = 100e6 / size_of_mapscr;
4548 void zmap::CapCommandHistory()
4549 {
4550 int size;
4551 do
4552 {
4553 size = 0;
4554 for (auto command : undo_stack)
4555 {
4556 size += command->size();
4557 }
4558 if (size > max_command_size) undo_stack.pop_front();
4559 } while (size > max_command_size);
4560 }
4561
4562 void zmap::DoSetComboCommand(ComboPosition pos, int combo, int cset)
4563 {
4564 if (!pos.is_valid(cursor))
4565 return;
4566
4567 int map = cursor.map;
4568 int screen = cursor.viewscr + pos.screen_offset();
4569 if (!AbsoluteScr(map, screen))
4570 return;
4571
4572 if (CurrentLayer)
4573 {
4574 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4575 map = scr->layermap[CurrentLayer-1]-1;
4576 screen = scr->layerscreen[CurrentLayer-1];
4577 }
4578 DoSetComboCommand(map, screen, pos.truncate(), combo, cset);
4579 }
4580
4581 void zmap::DoSetComboCommand(int map, int scr, int pos, int combo, int cset)
4582 {
4583 mapscr* mapscr_ptr = AbsoluteScrMakeValid(map, scr);
4584 if (!mapscr_ptr) return;
4585
4586 std::shared_ptr<set_combo_command> command(new set_combo_command);
4587 command->cursor = cursor;
4588 command->map = map;
4589 command->scr = scr;
4590 command->pos = pos;
4591 command->combo = combo;
4592 command->cset = cset;
4593 command->prev_combo = mapscr_ptr->data[pos];
4594 command->prev_cset = mapscr_ptr->cset[pos];
4595 if ((command->combo != -1 && command->prev_combo == command->combo) && command->cset == command->prev_cset)
4596 {
4597 // nothing to do...
4598 return;
4599 }
4600
4601 ExecuteCommand(command);
4602 }
4603
4604 void zmap::DoSetFFCCommand(int map, int scr, int i, set_ffc_command::data_t data)
4605 {
4606 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4607 if(!mapscr_ptr) return;
4608
4609 mapscr_ptr->ensureFFC(i);
4610
4611 std::shared_ptr<set_ffc_command> command(new set_ffc_command);
4612
4613 std::array<int, 8> initd_arr;
4614 std::copy(std::begin(mapscr_ptr->ffcs[i].initd), std::end(mapscr_ptr->ffcs[i].initd), initd_arr.begin());
4615
4616 auto prev_data = set_ffc_command::create_data(mapscr_ptr->ffcs[i]);
4617
4618 command->cursor = cursor;
4619 command->map = map;
4620 command->scr = scr;
4621 command->i = i;
4622 command->data = data;
4623 command->prev_data = prev_data;
4624 if (data == prev_data)
4625 {
4626 // nothing to do...
4627 return;
4628 }
4629
4630 ExecuteCommand(command);
4631 }
4632
4633 void zmap::DoSetFlagCommand(ComboPosition pos, int flag)
4634 {
4635 if (!pos.is_valid(cursor))
4636 return;
4637
4638 int map = cursor.map;
4639 int screen = cursor.viewscr + pos.screen_offset();
4640 if (!AbsoluteScr(map, screen))
4641 return;
4642
4643 if (CurrentLayer)
4644 {
4645 mapscr* scr = AbsoluteScrMakeValid(map, screen);
4646 map = scr->layermap[CurrentLayer-1]-1;
4647 screen = scr->layerscreen[CurrentLayer-1];
4648 }
4649 DoSetFlagCommand(map, screen, pos.truncate(), flag);
4650 }
4651
4652 void zmap::DoSetFlagCommand(int map, int scr, int pos, int flag)
4653 {
4654 mapscr* mapscr_ptr = Map.AbsoluteScr(map, scr);
4655 if(!mapscr_ptr) return;
4656
4657 std::shared_ptr<set_flag_command> command(new set_flag_command);
4658 command->cursor = cursor;
4659 command->map = map;
4660 command->scr = scr;
4661 command->pos = pos;
4662 command->flag = flag;
4663 command->prev_flag = mapscr_ptr->sflag[pos];
4664 if (command->flag == command->prev_flag)
4665 {
4666 // nothing to do...
4667 return;
4668 }
4669
4670 ExecuteCommand(command);
4671 }
4672
4673 void zmap::DoSetDoorCommand(int scr, int side, int door)
4674 {
4675 if(screens[scr].door[side] == door)
4676 return;
4677 std::shared_ptr<set_door_command> command(new set_door_command);
4678 command->cursor = cursor;
4679 command->side = side;
4680 command->door = door;
4681 command->prev_door = screens[scr].door[side];
4682
4683 ExecuteCommand(command);
4684 }
4685 void zmap::DoSetDCSCommand(int dcs)
4686 {
4687 if(screens[cursor.screen].door_combo_set == dcs)
4688 return;
4689 std::shared_ptr<set_dcs_command> command(new set_dcs_command);
4690 command->cursor = cursor;
4691 command->dcs = dcs;
4692 command->prev_dcs = screens[cursor.screen].door_combo_set;
4693
4694 ExecuteCommand(command);
4695 }
4696
4697 void zmap::DoPasteScreenCommand(PasteCommandType type, int screen)
4698 {
4699 if (screen == -1)
4700 screen = cursor.screen;
4701
4702 std::shared_ptr<paste_screen_command> command(new paste_screen_command);
4703 command->cursor = cursor;
4704 command->type = type;
4705 command->screen = std::shared_ptr<mapscr>(new mapscr(copymapscr));
4706 command->screen_index = screen;
4707
4708 if (type == PasteCommandType::ScreenPartialToEveryScreen || type == PasteCommandType::ScreenAllToEveryScreen)
4709 {
4710 for (int i=0; i < 128; i++)
4711 {
4712 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[i])));
4713 }
4714 }
4715 else
4716 {
4717 command->prev_screens.push_back(std::shared_ptr<mapscr>(new mapscr(screens[screen])));
4718 }
4719
4720 ExecuteCommand(command);
4721 }
4722
4723 void zmap::DoClearScreenCommand(int screen)
4724 {
4725 std::shared_ptr<set_screen_command> command(new set_screen_command);
4726 command->cursor = cursor;
4727 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(screens[screen]));
4728 command->screen = std::shared_ptr<mapscr>(nullptr);
4729 command->screen_index = screen;
4730
4731 ExecuteCommand(command);
4732 }
4733
4734 void zmap::DoTemplateCommand(int floorcombo, int floorcset, int screen)
4735 {
4736 std::shared_ptr<set_screen_command> command(new set_screen_command);
4737 command->cursor = cursor;
4738 command->prev_screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4739 Template(floorcombo, floorcset, screen);
4740 command->screen = std::shared_ptr<mapscr>(new mapscr(*Map.Scr(screen)));
4741
4742 ExecuteCommand(command, true);
4743 }
4744
4745 void zmap::Copy(int scr)
4746 {
4747 if(screens[scr].valid&mVALID)
4748 {
4749 copy_mapscr(&copymapscr, &screens[scr]);
4750 //copymapscr=screens[scr];
4751 can_paste=true;
4752 copymap=cursor.map;
4753 copyscr=scr;
4754 copyscrdata = zinit.screen_data[cursor.map*MAPSCRS+scr];
4755 copyffc = -1;
4756 }
4757 }
4758
4759 void zmap::CopyFFC(int32_t screen, int32_t n)
4760 {
4761 if(screens[screen].valid&mVALID)
4762 {
4763 copy_mapscr(&copymapscr, &screens[screen]);
4764 // Can't paste the screen itself
4765 can_paste = false;
4766 copymap=cursor.map;
4767 copyscr=screen;
4768 copyffc = n;
4769 }
4770 }
4771
4772 void zmap::Paste(const mapscr& copymapscr, int screen)
4773 {
4774 if(can_paste)
4775 {
4776 if(!(screens[screen].valid&mVALID))
4777 {
4778 screens[screen].valid |= mVALID;
4779 screens[screen].color = copymapscr.color;
4780 }
4781
4782 screens[screen].door_combo_set = copymapscr.door_combo_set;
4783
4784 for(int32_t i=0; i<4; i++)
4785 {
4786 screens[screen].door[i]=copymapscr.door[i];
4787 }
4788
4789 for(int32_t i=0; i<176; i++)
4790 {
4791 screens[screen].data[i] = copymapscr.data[i];
4792 screens[screen].cset[i] = copymapscr.cset[i];
4793 screens[screen].sflag[i] = copymapscr.sflag[i];
4794 }
4795
4796 refresh_color();
4797
4798 saved=false;
4799 }
4800 }
4801
4802 void zmap::PasteUnderCombo(const mapscr& copymapscr, int screen)
4803 {
4804 if(can_paste)
4805 {
4806 screens[screen].undercombo = copymapscr.undercombo;
4807 screens[screen].undercset = copymapscr.undercset;
4808 saved=false;
4809 }
4810 }
4811
4812 void zmap::PasteSecretCombos(const mapscr& copymapscr, int screen)
4813 {
4814 if(can_paste)
4815 {
4816 for(int32_t i=0; i<128; i++)
4817 {
4818 screens[screen].secretcombo[i] = copymapscr.secretcombo[i];
4819 screens[screen].secretcset[i] = copymapscr.secretcset[i];
4820 screens[screen].secretflag[i] = copymapscr.secretflag[i];
4821 }
4822
4823 saved=false;
4824 }
4825 }
4826
4827 // TODO const mapscr& copymapscr
4828 void zmap::PasteFFCombos(mapscr& copymapscr, int screen)
4829 {
4830 if(can_paste)
4831 {
4832 screens[screen].ffcs = copymapscr.ffcs;
4833 screens[screen].ffcCountMarkDirty();
4834 saved=false;
4835 }
4836 }
4837
4838 void zmap::PasteWarps(const mapscr& copymapscr, int screen)
4839 {
4840 if(can_paste)
4841 {
4842 screens[screen].sidewarpindex = copymapscr.sidewarpindex;
4843
4844 for(int32_t i=0; i<4; i++)
4845 {
4846 screens[screen].tilewarptype[i] = copymapscr.tilewarptype[i];
4847 screens[screen].tilewarpdmap[i] = copymapscr.tilewarpdmap[i];
4848 screens[screen].tilewarpscr[i] = copymapscr.tilewarpscr[i];
4849 screens[screen].sidewarptype[i] = copymapscr.sidewarptype[i];
4850 screens[screen].sidewarpdmap[i] = copymapscr.sidewarpdmap[i];
4851 screens[screen].sidewarpscr[i] = copymapscr.sidewarpscr[i];
4852 screens[screen].flags2 &= ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4853 screens[screen].flags2 |= copymapscr.flags2 & (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4854 screens[screen].sidewarpoverlayflags = copymapscr.sidewarpoverlayflags;
4855 screens[screen].tilewarpoverlayflags = copymapscr.tilewarpoverlayflags;
4856 }
4857
4858 saved=false;
4859 }
4860 }
4861
4862 void zmap::PasteScreenData(const mapscr& copymapscr, int screen)
4863 {
4864 if(can_paste)
4865 {
4866 screens[screen].csensitive = copymapscr.csensitive;
4867 screens[screen].oceansfx = copymapscr.oceansfx;
4868 screens[screen].bosssfx = copymapscr.bosssfx;
4869 screens[screen].secretsfx = copymapscr.secretsfx;
4870 screens[screen].holdupsfx = copymapscr.holdupsfx;
4871 screens[screen].flags = copymapscr.flags;
4872 screens[screen].flags2 &= (wfUP|wfDOWN|wfLEFT|wfRIGHT);
4873 screens[screen].flags2 |= copymapscr.flags2 & ~(wfUP|wfDOWN|wfLEFT|wfRIGHT);
4874 screens[screen].flags3 = copymapscr.flags3;
4875 screens[screen].flags4 = copymapscr.flags4;
4876 screens[screen].flags5 = copymapscr.flags5;
4877 screens[screen].flags6 = copymapscr.flags6;
4878 screens[screen].flags7 = copymapscr.flags7;
4879 screens[screen].flags8 = copymapscr.flags8;
4880 screens[screen].flags9 = copymapscr.flags9;
4881 screens[screen].flags10 = copymapscr.flags10;
4882 screens[screen].flags11 = copymapscr.flags11;
4883 screens[screen].item = copymapscr.item;
4884 screens[screen].hasitem = copymapscr.hasitem;
4885 screens[screen].itemx = copymapscr.itemx;
4886 screens[screen].itemy = copymapscr.itemy;
4887 screens[screen].nextmap = copymapscr.nextmap;
4888 screens[screen].nextscr = copymapscr.nextscr;
4889 screens[screen].nocarry = copymapscr.nocarry;
4890 screens[screen].noreset = copymapscr.noreset;
4891 screens[screen].exstate_reset = copymapscr.exstate_reset;
4892 screens[screen].exstate_carry = copymapscr.exstate_carry;
4893 screens[screen].path[0] = copymapscr.path[0];
4894 screens[screen].path[1] = copymapscr.path[1];
4895 screens[screen].path[2] = copymapscr.path[2];
4896 screens[screen].path[3] = copymapscr.path[3];
4897 screens[screen].pattern = copymapscr.pattern;
4898 screens[screen].exitdir = copymapscr.exitdir;
4899 screens[screen].screen_midi = copymapscr.screen_midi;
4900 screens[screen].stairx = copymapscr.stairx;
4901 screens[screen].stairy = copymapscr.stairy;
4902 screens[screen].timedwarptics = copymapscr.timedwarptics;
4903 saved=false;
4904 }
4905 }
4906
4907 void zmap::PasteWarpLocations(const mapscr& copymapscr, int screen)
4908 {
4909 if(can_paste)
4910 {
4911 screens[screen].warpreturnc = copymapscr.warpreturnc;
4912 screens[screen].warparrivalx = copymapscr.warparrivalx;
4913 screens[screen].warparrivaly = copymapscr.warparrivaly;
4914
4915 for(int32_t i=0; i<4; i++)
4916 {
4917 screens[screen].warpreturnx[i] = copymapscr.warpreturnx[i];
4918 screens[screen].warpreturny[i] = copymapscr.warpreturny[i];
4919 }
4920
4921 saved=false;
4922 }
4923 }
4924
4925 void zmap::PasteDoors(const mapscr& copymapscr, int screen)
4926 {
4927 if(can_paste)
4928 {
4929 for(int32_t i=0; i<4; i++)
4930 screens[screen].door[i] = copymapscr.door[i];
4931
4932 screens[screen].door_combo_set = copymapscr.door_combo_set;
4933 saved=false;
4934 }
4935 }
4936
4937 void zmap::PasteLayers(const mapscr& copymapscr, int screen)
4938 {
4939 if(can_paste)
4940 {
4941 for(int32_t i=0; i<6; i++)
4942 {
4943 screens[screen].layermap[i] = copymapscr.layermap[i];
4944 screens[screen].layerscreen[i] = copymapscr.layerscreen[i];
4945 screens[screen].layeropacity[i] = copymapscr.layeropacity[i];
4946 }
4947
4948 saved=false;
4949 }
4950 }
4951
4952 void zmap::PasteRoom(const mapscr& copymapscr, int screen)
4953 {
4954 if(can_paste)
4955 {
4956 screens[screen].room = copymapscr.room;
4957 screens[screen].catchall = copymapscr.catchall;
4958 saved=false;
4959 }
4960 }
4961
4962 void zmap::PasteGuy(const mapscr& copymapscr, int screen)
4963 {
4964 if(can_paste)
4965 {
4966 screens[screen].guy = copymapscr.guy;
4967 screens[screen].guytile = copymapscr.guytile;
4968 screens[screen].guycs = copymapscr.guycs;
4969 SETFLAG(screens[screen].roomflags,RFL_ALWAYS_GUY,copymapscr.roomflags&RFL_ALWAYS_GUY);
4970 SETFLAG(screens[screen].roomflags,RFL_GUYFIRES,copymapscr.roomflags&RFL_GUYFIRES);
4971 screens[screen].str = copymapscr.str;
4972 saved=false;
4973 }
4974 }
4975
4976 void zmap::PastePalette(const mapscr& copymapscr, int screen)
4977 {
4978 if(can_paste)
4979 {
4980 screens[screen].color = copymapscr.color;
4981 screens[screen].valid|=mVALID;
4982 refresh_color();
4983
4984 saved=false;
4985 }
4986 }
4987
4988 void zmap::PasteAll(const mapscr& copymapscr, int screen)
4989 {
4990 if(can_paste)
4991 {
4992 copy_mapscr(&screens[screen], &copymapscr);
4993 zinit.screen_data[cursor.map*MAPSCRS+cursor.screen] = copyscrdata;
4994 screens[screen].valid|=mVALID;
4995
4996 refresh_color();
4997
4998 saved=false;
4999 }
5000 }
5001
5002
5003 void zmap::PasteToAll(const mapscr& copymapscr)
5004 {
5005 if(can_paste)
5006 {
5007 for(int32_t x=0; x<128; x++)
5008 {
5009 if(!(screens[x].valid&mVALID))
5010 {
5011 screens[x].valid |= mVALID;
5012 screens[x].color = copymapscr.color;
5013 }
5014
5015 for(int32_t i=0; i<176; i++)
5016 {
5017 screens[x].data[i] = copymapscr.data[i];
5018 screens[x].cset[i] = copymapscr.cset[i];
5019 screens[x].sflag[i] = copymapscr.sflag[i];
5020 }
5021 }
5022
5023 refresh_color();
5024
5025 saved=false;
5026 }
5027 }
5028
5029 void zmap::PasteAllToAll(const mapscr& copymapscr)
5030 {
5031 if(can_paste)
5032 {
5033 for(int32_t x=0; x<128; x++)
5034 {
5035 copy_mapscr(&screens[x], &copymapscr);
5036 zinit.screen_data[cursor.map*MAPSCRS+x] = copyscrdata;
5037 //screens[x]=copymapscr;
5038 }
5039
5040 refresh_color();
5041
5042 saved=false;
5043 }
5044 }
5045
5046 void zmap::PasteEnemies(const mapscr& copymapscr, int screen)
5047 {
5048 if(can_paste)
5049 {
5050 for(int32_t i=0; i<10; i++)
5051 screens[screen].enemy[i]=copymapscr.enemy[i];
5052 }
5053 }
5054
5055 void zmap::setCopyFFC(int32_t n)
5056 {
5057 copyffc = n;
5058 }
5059
5060 void zmap::update_combo_cycling()
5061 {
5062 if(!prv_mode||!prv_cmbcycle)
5063 {
5064 return;
5065 }
5066
5067 int32_t x;
5068 int32_t newdata[176];
5069 int32_t newcset[176];
5070 bool restartanim[MAXCOMBOS] = {0};
5071
5072 for(int32_t i=0; i<176; i++)
5073 {
5074 newdata[i]=-1;
5075 newcset[i]=-1;
5076
5077 x=prvscr.data[i];
5078
5079 //time to restart
5080 if((combobuf[x].aclk>=combobuf[x].speed) &&
5081 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5082 combobuf[x].can_cycle())
5083 {
5084 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5085 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5086
5087 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5088 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5089 int32_t c = newdata[i];
5090
5091 if(combobuf[c].animflags & AF_CYCLE)
5092 {
5093 restartanim[c]=true;
5094 }
5095 }
5096 }
5097
5098 for(int32_t i=0; i<176; i++)
5099 {
5100 x=prvscr.data[i];
5101
5102 //time to restart
5103 if((combobuf[x].aclk>=combobuf[x].speed) &&
5104 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5105 combobuf[x].can_cycle())
5106 {
5107 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5108 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5109
5110 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5111 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5112 int32_t c = newdata[i];
5113
5114 if(combobuf[c].animflags & AF_CYCLE)
5115 {
5116 restartanim[c]=true;
5117 }
5118 }
5119 }
5120
5121 for(int32_t i=0; i<176; i++)
5122 {
5123 if(newdata[i]==-1)
5124 continue;
5125
5126 prvscr.data[i]=newdata[i];
5127 prvscr.cset[i]=newcset[i];
5128 }
5129
5130 word maxffc = prvscr.numFFC();
5131 for(word i=0; i<maxffc; i++)
5132 {
5133 ffcdata& ffc = prvscr.ffcs[i];
5134 newcombo const& cmb = combobuf[ffc.data];
5135
5136 //time to restart
5137 if((cmb.aclk>=cmb.speed) &&
5138 (cmb.tile-cmb.frames>=cmb.o_tile-1) &&
5139 cmb.can_cycle())
5140 {
5141 bool cycle_under = (cmb.animflags & AF_CYCLEUNDERCOMBO);
5142 ffc.data = cycle_under ? prvscr.undercombo : cmb.nextcombo;
5143
5144 if(!(cmb.animflags & AF_CYCLENOCSET))
5145 newcset[i] = cycle_under ? prvscr.undercset : cmb.nextcset;
5146
5147 if(combobuf[ffc.data].animflags & AF_CYCLE)
5148 {
5149 restartanim[ffc.data]=true;
5150 }
5151 prvscr.ffcs[i].data = ffc.data;
5152 prvscr.ffcs[i].cset=ffc.cset;
5153 }
5154 }
5155
5156
5157 if(get_qr(qr_CMBCYCLELAYERS))
5158 {
5159 for(int32_t j=0; j<6; j++)
5160 {
5161 if(!prvlayers[j].valid)
5162 continue;
5163
5164 for(int32_t i=0; i<176; i++)
5165 {
5166 newdata[i]=-1;
5167 newcset[i]=-1;
5168
5169 x=(prvlayers[j]).data[i];
5170
5171 //time to restart
5172 if((combobuf[x].aclk>=combobuf[x].speed) &&
5173 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5174 combobuf[x].can_cycle())
5175 {
5176 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5177 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5178
5179 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5180 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5181 int32_t c = newdata[i];
5182
5183 if(combobuf[c].animflags & AF_CYCLE)
5184 {
5185 restartanim[c]=true;
5186 }
5187 }
5188 }
5189
5190 for(int32_t i=0; i<176; i++)
5191 {
5192 x=(prvlayers[j]).data[i];
5193
5194 //time to restart
5195 if((combobuf[x].aclk>=combobuf[x].speed) &&
5196 (combobuf[x].tile-combobuf[x].frames>=combobuf[x].o_tile-1) &&
5197 combobuf[x].can_cycle())
5198 {
5199 bool cycle_under = (combobuf[x].animflags & AF_CYCLEUNDERCOMBO);
5200 newdata[i] = cycle_under ? prvscr.undercombo : combobuf[x].nextcombo;
5201
5202 if(!(combobuf[x].animflags & AF_CYCLENOCSET))
5203 newcset[i] = cycle_under ? prvscr.undercset : combobuf[x].nextcset;
5204 int32_t c = newdata[i];
5205
5206 if(combobuf[c].animflags & AF_CYCLE)
5207 {
5208 restartanim[c]=true;
5209 }
5210 }
5211 }
5212
5213 for(int32_t i=0; i<176; i++)
5214 {
5215 if(newdata[i]==-1)
5216 continue;
5217
5218 prvlayers[j].data[i]=newdata[i];
5219 prvlayers[j].cset[i]=newcset[i];
5220 }
5221 }
5222 }
5223
5224 for(int32_t i=0; i<MAXCOMBOS; i++)
5225 {
5226 if(restartanim[i])
5227 {
5228 combobuf[i].tile = combobuf[i].o_tile;
5229 combobuf[i].cur_frame=0;
5230 combobuf[i].aclk = 0;
5231 }
5232 }
5233 }
5234
5235 void zmap::update_freeform_combos()
5236 {
5237 if(!prv_mode||!prv_cmbcycle)
5238 {
5239 return;
5240 }
5241
5242 // TODO: this changer code is a duplicated here and for zplayer. Should fix that.
5243 word maxffc = prvscr.numFFC();
5244 for(int32_t i=0; i<maxffc; i++)
5245 {
5246 if(!(prvscr.ffcs[i].flags&ffc_changer) && prvscr.ffcs[i].data!=0 && !(prvscr.ffcs[i].flags&ffc_stationary))
5247 {
5248 for(int32_t j=0; j<maxffc; j++)
5249 {
5250 if(i!=j)
5251 {
5252 if(prvscr.ffcs[j].flags&ffc_changer && prvscr.ffcs[j].data != 0)
5253 {
5254 if((((prvscr.ffcs[j].x.getInt())!=prvscr.ffcs[i].changer_x)||((prvscr.ffcs[j].y.getInt())!=prvscr.ffcs[i].changer_y))&&(prvscr.ffcs[i].link==0))
5255 {
5256 if((isonline(prvscr.ffcs[i].x.getZLong(),prvscr.ffcs[i].y.getZLong(),prvscr.ffcs[i].prev_changer_x,prvscr.ffcs[i].prev_changer_y,prvscr.ffcs[j].x.getZLong(),prvscr.ffcs[j].y.getZLong())||
5257 ((prvscr.ffcs[i].x.getZLong()==prvscr.ffcs[j].x.getZLong())&&(prvscr.ffcs[i].y.getZLong()==prvscr.ffcs[j].y.getZLong())))&&(prvscr.ffcs[i].prev_changer_x>-10000000&&prvscr.ffcs[i].prev_changer_y>-10000000))
5258 {
5259 //prvscr.ffcs[i].data=prvscr.ffcs[j].data;
5260 //prvscr.ffcs[i].cset=prvscr.ffcs[j].cset;
5261 if(prvscr.ffcs[j].flags&ffc_changethis)
5262 {
5263 prvscr.ffcs[i].data = prvscr.ffcs[j].data;
5264 prvscr.ffcs[i].cset = prvscr.ffcs[j].cset;
5265 }
5266
5267 if(prvscr.ffcs[j].flags&ffc_changenext)
5268 prvscr.ffcs[i].data += 1;
5269
5270 if(prvscr.ffcs[j].flags&ffc_changeprev)
5271 prvscr.ffcs[i].data -= 1;
5272
5273 prvscr.ffcs[i].delay=prvscr.ffcs[j].delay;
5274 prvscr.ffcs[i].x=prvscr.ffcs[j].x;
5275 prvscr.ffcs[i].y=prvscr.ffcs[j].y;
5276
5277 prvscr.ffcs[i].vx=prvscr.ffcs[j].vx;
5278 prvscr.ffcs[i].vy=prvscr.ffcs[j].vy;
5279 prvscr.ffcs[i].ax=prvscr.ffcs[j].ax;
5280 prvscr.ffcs[i].ay=prvscr.ffcs[j].ay;
5281
5282 prvscr.ffcs[i].link=prvscr.ffcs[j].link;
5283 prvscr.ffcs[i].hit_width=prvscr.ffcs[j].hit_width;
5284 prvscr.ffcs[i].hit_height=prvscr.ffcs[j].hit_height;
5285 prvscr.ffcs[i].txsz=prvscr.ffcs[j].txsz;
5286 prvscr.ffcs[i].tysz=prvscr.ffcs[j].tysz;
5287
5288 if(prvscr.ffcs[i].flags&ffc_carryover)
5289 prvscr.ffcs[i].flags=prvscr.ffcs[j].flags&ffc_carryover;
5290 else prvscr.ffcs[i].flags=prvscr.ffcs[j].flags;
5291
5292 prvscr.ffcs[i].flags&=~ffc_changer;
5293 prvscr.ffcs[i].changer_x=(prvscr.ffcs[j].x.getInt());
5294 prvscr.ffcs[i].changer_y=(prvscr.ffcs[j].y.getInt());
5295
5296 if(combobuf[prvscr.ffcs[j].data].flag>15 && combobuf[prvscr.ffcs[j].data].flag<32)
5297 {
5298 prvscr.ffcs[j].data = prvscr.secretcombo[combobuf[prvscr.ffcs[j].data].flag - 16 + 4];
5299 }
5300
5301 if((prvscr.ffcs[j].flags&ffc_swapnext)||(prvscr.ffcs[j].flags&ffc_swapprev))
5302 {
5303 int32_t k=0;
5304
5305 if(prvscr.ffcs[j].flags&ffc_swapnext)
5306 k=j<(MAXFFCS-1)?j+1:0;
5307
5308 if(prvscr.ffcs[j].flags&ffc_swapprev)
5309 k=j>0?j-1:(MAXFFCS-1);
5310
5311 zc_swap(prvscr.ffcs[j].vx,prvscr.ffcs[k].vx);
5312 zc_swap(prvscr.ffcs[j].vy,prvscr.ffcs[k].vy);
5313 zc_swap(prvscr.ffcs[j].ax,prvscr.ffcs[k].ax);
5314 zc_swap(prvscr.ffcs[j].ay,prvscr.ffcs[k].ay);
5315 zc_swap(prvscr.ffcs[j].link,prvscr.ffcs[k].link);
5316 zc_swap(prvscr.ffcs[j].hit_width,prvscr.ffcs[k].hit_width);
5317 zc_swap(prvscr.ffcs[j].hit_height,prvscr.ffcs[k].hit_height);
5318 zc_swap(prvscr.ffcs[j].txsz,prvscr.ffcs[k].txsz);
5319 zc_swap(prvscr.ffcs[j].tysz,prvscr.ffcs[k].tysz);
5320 zc_swap(prvscr.ffcs[j].flags,prvscr.ffcs[k].flags);
5321 }
5322 }
5323 }
5324 }
5325 }
5326 }
5327
5328 if(prvscr.ffcs[i].link ? !prvscr.ffcs[prvscr.ffcs[i].link].delay : !prvscr.ffcs[i].delay)
5329 {
5330 if(prvscr.ffcs[i].link&&(prvscr.ffcs[i].link-1)!=i)
5331 {
5332 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5333 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5334 prvscr.ffcs[i].x+=prvscr.ffcs[prvscr.ffcs[i].link-1].vx;
5335 prvscr.ffcs[i].y+=prvscr.ffcs[prvscr.ffcs[i].link-1].vy;
5336 }
5337 else
5338 {
5339 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5340 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5341 prvscr.ffcs[i].x+=prvscr.ffcs[i].vx;
5342 prvscr.ffcs[i].y+=prvscr.ffcs[i].vy;
5343 prvscr.ffcs[i].vx+=prvscr.ffcs[i].ax;
5344 prvscr.ffcs[i].vy+=prvscr.ffcs[i].ay;
5345
5346 if(get_qr(qr_OLD_FFC_SPEED_CAP))
5347 {
5348 if(prvscr.ffcs[i].vx>128) prvscr.ffcs[i].vx=128;
5349
5350 if(prvscr.ffcs[i].vx<-128) prvscr.ffcs[i].vx=-128;
5351
5352 if(prvscr.ffcs[i].vy>128) prvscr.ffcs[i].vy=128;
5353
5354 if(prvscr.ffcs[i].vy<-128) prvscr.ffcs[i].vy=-128;
5355 }
5356 }
5357 }
5358 else
5359 {
5360 if(!prvscr.ffcs[i].link || (prvscr.ffcs[i].link-1)==i)
5361 prvscr.ffcs[i].delay--;
5362 }
5363
5364 if(prvscr.ffcs[i].x<-32)
5365 {
5366 if(prvscr.flags6&fWRAPAROUNDFF)
5367 {
5368 prvscr.ffcs[i].x = (288+(prvscr.ffcs[i].x+32));
5369 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5370 }
5371 else
5372 {
5373 prvscr.ffcs[i].data = 0;
5374 prvscr.ffcs[i].flags&=~ffc_carryover;
5375 }
5376 }
5377
5378 if(prvscr.ffcs[i].y<-32)
5379 {
5380 if(prvscr.flags6&fWRAPAROUNDFF)
5381 {
5382 prvscr.ffcs[i].y = 208+(prvscr.ffcs[i].y+32);
5383 prvscr.ffcs[i].prev_changer_x = prvscr.ffcs[i].x.getZLong();
5384 }
5385 else
5386 {
5387 prvscr.ffcs[i].data = 0;
5388 prvscr.ffcs[i].flags&=~ffc_carryover;
5389 }
5390 }
5391
5392 if(prvscr.ffcs[i].x>=288)
5393 {
5394 if(prvscr.flags6&fWRAPAROUNDFF)
5395 {
5396 prvscr.ffcs[i].x = prvscr.ffcs[i].x-288-32;
5397 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].y.getZLong();
5398 }
5399 else
5400 {
5401 prvscr.ffcs[i].data = 0;
5402 prvscr.ffcs[i].flags&=~ffc_carryover;
5403 }
5404 }
5405
5406 if(prvscr.ffcs[i].y>=208)
5407 {
5408 if(prvscr.flags6&fWRAPAROUNDFF)
5409 {
5410 prvscr.ffcs[i].y = prvscr.ffcs[i].y-208-32;
5411 prvscr.ffcs[i].prev_changer_y = prvscr.ffcs[i].x.getZLong();
5412 }
5413 else
5414 {
5415 prvscr.ffcs[i].data = 0;
5416 prvscr.ffcs[i].flags&=~ffc_carryover;
5417 }
5418 }
5419
5420 }
5421 }
5422 }
5423
5424 void zmap::goto_dmapscr(int dmap, int scr)
5425 {
5426 setCurrMap(DMaps[dmap].map);
5427 setCurrScr(scr+DMaps[dmap].xoff);
5428 }
5429 void zmap::goto_mapscr(int map, int scr)
5430 {
5431 setCurrMap(map);
5432 setCurrScr(scr);
5433 }
5434
5435 void zmap::dowarp(int32_t type, int32_t index)
5436 {
5437 set_warpback();
5438 if(type==0)
5439 {
5440
5441 int32_t dmap=screens[cursor.screen].tilewarpdmap[index];
5442 int32_t scr=screens[cursor.screen].tilewarpscr[index];
5443
5444 switch(screens[cursor.screen].tilewarptype[index])
5445 {
5446 case wtCAVE:
5447 case wtNOWARP:
5448 break;
5449
5450 default:
5451 goto_dmapscr(dmap, scr);
5452 break;
5453 }
5454 }
5455 else if(type==1)
5456 {
5457 int32_t dmap=screens[cursor.screen].sidewarpdmap[index];
5458 int32_t scr=screens[cursor.screen].sidewarpscr[index];
5459
5460 switch(screens[cursor.screen].sidewarptype[index])
5461 {
5462 case wtCAVE:
5463 case wtNOWARP:
5464 break;
5465
5466 default:
5467 goto_dmapscr(dmap, scr);
5468 break;
5469 }
5470 }
5471 }
5472
5473 extern int32_t prv_twon;
5474
5475 void zmap::prv_dowarp(int32_t type, int32_t index)
5476 {
5477 if(type==0)
5478 {
5479
5480 int32_t dmap=prvscr.tilewarpdmap[index];
5481 int32_t scr=prvscr.tilewarpscr[index];
5482
5483 switch(prvscr.tilewarptype[index])
5484 {
5485 case wtCAVE:
5486 case wtNOWARP:
5487 break;
5488
5489 default:
5490 //setCurrMap(DMaps[dmap].map);
5491 //setCurrScr(scr+DMaps[dmap].xoff);
5492 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5493 refresh_color();
5494 //prv_cmbcycle=0;
5495 break;
5496 }
5497 }
5498 else if(type==1)
5499 {
5500 int32_t dmap=prvscr.sidewarpdmap[index];
5501 int32_t scr=prvscr.sidewarpscr[index];
5502
5503 switch(prvscr.sidewarptype[index])
5504 {
5505 case wtCAVE:
5506 case wtNOWARP:
5507 break;
5508
5509 default:
5510 //setCurrMap(DMaps[dmap].map);
5511 //setCurrScr(scr+DMaps[dmap].xoff);
5512 set_prvscr(DMaps[dmap].map,scr+DMaps[dmap].xoff);
5513 refresh_color();
5514 //prv_cmbcycle=0;
5515 break;
5516 }
5517 }
5518
5519 if(prv_twon)
5520 {
5521 prv_time=get_prvscr()->timedwarptics;
5522 }
5523 }
5524
5525 void zmap::dowarp2(int32_t ring,int32_t index)
5526 {
5527 set_warpback();
5528 goto_dmapscr(QMisc.warp[ring].dmap[index], QMisc.warp[ring].scr[index]);
5529 }
5530
5531 void zmap::set_warpback()
5532 {
5533 warpbackmap = cursor.map;
5534 warpbackscreen = cursor.screen;
5535 }
5536 bool zmap::has_warpback()
5537 {
5538 return warpbackmap && warpbackscreen
5539 && !(warpbackmap == cursor.map && warpbackscreen == cursor.screen);
5540 }
5541 void zmap::warpback()
5542 {
5543 if(!has_warpback())
5544 return;
5545
5546 int m = cursor.map, s = cursor.screen;
5547 goto_mapscr(*warpbackmap, *warpbackscreen);
5548 warpbackmap = m;
5549 warpbackscreen = s;
5550 }
5551
5552 bool save_msgstrs(const char *path)
5553 {
5554 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5555
5556 if(!f)
5557 {
5558 return false;
5559 }
5560
5561 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)==0)
5562 {
5563 pack_fclose(f);
5564 return true;
5565 }
5566
5567 pack_fclose(f);
5568 return false;
5569 }
5570
5571 1 bool save_strings_tsv(const char *path)
5572 {
5573 1 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5574
5575
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(!f)
5576 {
5577 return false;
5578 }
5579
5580
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(writestrings_tsv(f)==0)
5581 {
5582 1 pack_fclose(f);
5583 1 return true;
5584 }
5585
5586 pack_fclose(f);
5587 return false;
5588 1 }
5589
5590 bool save_msgstrs_text(const char *path)
5591 {
5592 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5593
5594 if(!f)
5595 {
5596 return false;
5597 }
5598
5599 if(writestrings_text(f)==0)
5600 {
5601 pack_fclose(f);
5602 return true;
5603 }
5604
5605 pack_fclose(f);
5606 return false;
5607 }
5608
5609 bool load_msgstrs(const char *path, int32_t startstring)
5610 {
5611 //these are here to bypass compiler warnings about unused arguments
5612 startstring=startstring;
5613
5614 dword section_id;
5615 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5616
5617 if(!f)
5618 {
5619 return false;
5620 }
5621
5622 if(!p_mgetl(&section_id,f))
5623 {
5624 return false;
5625 }
5626
5627 if(section_id==ID_STRINGS)
5628 {
5629 if(readstrings(f, &header)==0)
5630 {
5631 pack_fclose(f);
5632 return true;
5633 }
5634 else
5635 {
5636 pack_fclose(f);
5637 return false;
5638 }
5639 }
5640
5641 pack_fclose(f);
5642 return false;
5643 }
5644
5645 bool load_strings_tsv(const char *path)
5646 {
5647 try
5648 {
5649 parse_strings_tsv(util::read_text_file(path));
5650 }
5651 catch (std::exception& ex)
5652 {
5653 InfoDialog("Import .tsv Error", ex.what()).show();
5654 return false;
5655 }
5656 return true;
5657 }
5658
5659 bool save_pals(const char *path)
5660 {
5661 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5662
5663 if(!f)
5664 {
5665 return false;
5666 }
5667
5668 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)==0)
5669 {
5670 pack_fclose(f);
5671 return true;
5672 }
5673
5674 pack_fclose(f);
5675 return false;
5676 }
5677
5678 bool load_pals(const char *path, int32_t startcset)
5679 {
5680 dword section_id;
5681 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5682
5683 if(!f)
5684 {
5685 return false;
5686 }
5687
5688 if(!p_mgetl(&section_id,f))
5689 {
5690 return false;
5691 }
5692
5693 if(section_id==ID_CSETS)
5694 {
5695 if(readcolordata(f, &QMisc, 0x250, 33, startcset, newerpdTOTAL-startcset)==0)
5696 {
5697 pack_fclose(f);
5698 loadlvlpal(Color);
5699 return true;
5700 }
5701 else
5702 {
5703 pack_fclose(f);
5704 return false;
5705 }
5706 }
5707
5708 return false;
5709 }
5710
5711 int32_t writeguys(PACKFILE *f, zquestheader *Header);
5712 bool save_guys(const char *path)
5713 {
5714 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5715
5716 if(!f)
5717 {
5718 return false;
5719 }
5720
5721 /*
5722 int32_t id = ID_GUYS;
5723 if(!p_mputl(id,f))
5724 {
5725 return false;
5726 }
5727 */
5728
5729 zquestheader h;
5730 h.zelda_version = 0x250;
5731 h.build = 21;
5732
5733 if(writeguys(f, &h)==0)
5734 {
5735 pack_fclose(f);
5736 return true;
5737 }
5738
5739 pack_fclose(f);
5740 return false;
5741 }
5742
5743 bool load_guys(const char *path)
5744 {
5745 dword section_id;
5746 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5747
5748 if(!f)
5749 {
5750 return false;
5751 }
5752
5753 if(!p_mgetl(&section_id,f))
5754 {
5755 pack_fclose(f);
5756 return false;
5757 }
5758
5759 zquestheader h;
5760 h.zelda_version = 0x250;
5761 h.build = 21;
5762
5763 if(section_id==ID_GUYS)
5764 {
5765 if(readguys(f, &h)==0)
5766 {
5767 pack_fclose(f);
5768 return true;
5769 }
5770 }
5771
5772 pack_fclose(f);
5773 return false;
5774 }
5775
5776
5777 //int32_t writeguys(PACKFILE *f, zquestheader *Header);
5778 bool save_combo_alias(const char *path)
5779 {
5780 PACKFILE *f = pack_fopen_password(path,F_WRITE, "");
5781
5782 if(!f)
5783 {
5784 return false;
5785 }
5786
5787 zquestheader h;
5788 h.zelda_version = 0x250;
5789 h.build = 21;
5790
5791 if(writecomboaliases(f, 0, 0)==0)
5792 {
5793 pack_fclose(f);
5794 return true;
5795 }
5796
5797 pack_fclose(f);
5798 return false;
5799 }
5800
5801 bool load_combo_alias(const char *path)
5802 {
5803 dword section_id;
5804 PACKFILE *f = pack_fopen_password(path,F_READ, "");
5805
5806 if(!f)
5807 {
5808 return false;
5809 }
5810
5811 if(!p_mgetl(&section_id,f))
5812 {
5813 pack_fclose(f);
5814 return false;
5815 }
5816
5817 zquestheader h;
5818 h.zelda_version = 0x250;
5819 h.build = 21;
5820
5821 if(section_id==ID_COMBOALIASES)
5822 {
5823 if(readcomboaliases(f, &h, 0, 0)==0)
5824 {
5825 pack_fclose(f);
5826 return true;
5827 }
5828 }
5829
5830 pack_fclose(f);
5831 return false;
5832 }
5833
5834 bool load_zgp(const char *path)
5835 {
5836 dword section_id;
5837 word section_version;
5838 PACKFILE *f=pack_fopen_password(path,F_READ,"");
5839
5840 if(!f)
5841 return false;
5842
5843 if(!p_mgetl(&section_id,f))
5844 {
5845 pack_fclose(f);
5846 return false;
5847 }
5848
5849 if(section_id!=ID_GRAPHICSPACK)
5850 {
5851 pack_fclose(f);
5852 return false;
5853 }
5854
5855 //section version info
5856 if(!p_igetw(&section_version,f))
5857 {
5858 return 2;
5859 }
5860
5861 if(!read_deprecated_section_cversion(f))
5862 {
5863 return 3;
5864 }
5865
5866 //tiles
5867 if(!p_mgetl(&section_id,f))
5868 {
5869 pack_fclose(f);
5870 return false;
5871 }
5872
5873 if(section_id==ID_TILES)
5874 {
5875 if(readtiles(f, newtilebuf, NULL, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES, false)!=0)
5876 {
5877 pack_fclose(f);
5878 init_tiles(true, &header);
5879 return false;
5880 }
5881 }
5882 else
5883 {
5884 pack_fclose(f);
5885 return false;
5886 }
5887
5888 //combos
5889 if(!p_mgetl(&section_id,f))
5890 {
5891 pack_fclose(f);
5892 return false;
5893 }
5894
5895 if(section_id==ID_COMBOS)
5896 {
5897 if(readcombos(f, NULL, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
5898 {
5899 pack_fclose(f);
5900 return false;
5901 }
5902 }
5903 else
5904 {
5905 pack_fclose(f);
5906 return false;
5907 }
5908
5909 //palettes
5910 if(!p_mgetl(&section_id,f))
5911 {
5912 pack_fclose(f);
5913 return false;
5914 }
5915
5916 if(section_id==ID_CSETS)
5917 {
5918 if(readcolordata(f, &QMisc, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
5919 {
5920 pack_fclose(f);
5921 return false;
5922 }
5923 }
5924 else
5925 {
5926 pack_fclose(f);
5927 return false;
5928 }
5929
5930 //items
5931 if(!p_mgetl(&section_id,f))
5932 {
5933 pack_fclose(f);
5934 return false;
5935 }
5936
5937 if(section_id==ID_ITEMS)
5938 {
5939 if(readitems(f, ZELDA_VERSION, VERSION_BUILD)!=0)
5940 {
5941 pack_fclose(f);
5942 return false;
5943 }
5944 }
5945 else
5946 {
5947 pack_fclose(f);
5948 return false;
5949 }
5950
5951 //weapons
5952 if(!p_mgetl(&section_id,f))
5953 {
5954 pack_fclose(f);
5955 return false;
5956 }
5957
5958 if(section_id==ID_WEAPONS)
5959 {
5960 if(readweapons(f, &header)!=0)
5961 {
5962 pack_fclose(f);
5963 return false;
5964 }
5965 }
5966 else
5967 {
5968 pack_fclose(f);
5969 return false;
5970 }
5971
5972 //read the triforce pieces info and make sure it worked
5973 //really do this?
5974
5975 //read the game icons info and make sure it worked
5976 if(!p_mgetl(&section_id,f))
5977 {
5978 pack_fclose(f);
5979 return false;
5980 }
5981
5982 if(section_id==ID_ICONS)
5983 {
5984 if(readgameicons(f, &header, &QMisc)!=0)
5985 {
5986 pack_fclose(f);
5987 return false;
5988 }
5989 }
5990 else
5991 {
5992 pack_fclose(f);
5993 return false;
5994 }
5995
5996 //read the misc colors info and map styles info and make sure it worked
5997 if(!p_mgetl(&section_id,f))
5998 {
5999 pack_fclose(f);
6000 return false;
6001 }
6002
6003 if(section_id==ID_COLORS)
6004 {
6005 if(readmisccolors(f, &header, &QMisc)!=0)
6006 {
6007 pack_fclose(f);
6008 return false;
6009 }
6010 }
6011 else
6012 {
6013 pack_fclose(f);
6014 return false;
6015 }
6016
6017 //read the door combo sets and make sure it worked
6018 if(!p_mgetl(&section_id,f))
6019 {
6020 pack_fclose(f);
6021 return false;
6022 }
6023
6024 if(section_id==ID_DOORS)
6025 {
6026 if(readdoorcombosets(f, &header)!=0)
6027 {
6028 pack_fclose(f);
6029 return false;
6030 }
6031 }
6032 else
6033 {
6034 pack_fclose(f);
6035 return false;
6036 }
6037
6038 //read the template screens and make sure it worked
6039 //really do this?
6040
6041 //yay! it worked! close the file and say everything was ok.
6042 loadlvlpal(Color);
6043 setup_combo_animations();
6044 setup_combo_animations2();
6045 pack_fclose(f);
6046 return true;
6047 }
6048
6049 bool save_zgp(const char *path)
6050 {
6051 reset_combo_animations();
6052 reset_combo_animations2();
6053
6054 //open the file
6055 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6056
6057 if(!f)
6058 return false;
6059
6060 dword section_id=ID_GRAPHICSPACK;
6061 dword section_version=V_GRAPHICSPACK;
6062
6063 //section id
6064 if(!p_mputl(section_id,f))
6065 {
6066 return 1;
6067 }
6068
6069 //section version info
6070 if(!p_iputw(section_version,f))
6071 {
6072 return 2;
6073 }
6074
6075 if(!write_deprecated_section_cversion(section_version,f))
6076 {
6077 return 3;
6078 }
6079
6080 //tiles
6081 if(writetiles(f, ZELDA_VERSION, VERSION_BUILD, 0, NEWMAXTILES)!=0)
6082 {
6083 pack_fclose(f);
6084 return false;
6085 }
6086
6087 //combos
6088 if(writecombos(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXCOMBOS)!=0)
6089 {
6090 pack_fclose(f);
6091 return false;
6092 }
6093
6094 //palettes
6095 if(writecolordata(f, ZELDA_VERSION, VERSION_BUILD, 0, newerpdTOTAL)!=0)
6096 {
6097 pack_fclose(f);
6098 return false;
6099 }
6100
6101 //items
6102 if(writeitems(f, &header)!=0)
6103 {
6104 pack_fclose(f);
6105 return false;
6106 }
6107
6108 //weapons
6109 if(writeweapons(f, &header)!=0)
6110 {
6111 pack_fclose(f);
6112 return false;
6113 }
6114
6115 //write the triforce pieces info and make sure it worked
6116 //really do this?
6117
6118 //write the game icons info and make sure it worked
6119 if(writegameicons(f, &header)!=0)
6120 {
6121 pack_fclose(f);
6122 return false;
6123 }
6124
6125 //write the misc colors info and map styles info and make sure it worked
6126 if(writemisccolors(f, &header)!=0)
6127 {
6128 pack_fclose(f);
6129 return false;
6130 }
6131
6132 //write the door combo sets and make sure it worked
6133 if(writedoorcombosets(f, &header)!=0)
6134 {
6135 pack_fclose(f);
6136 return false;
6137 }
6138
6139 //write the template screens and make sure it worked
6140 //really do this?
6141
6142 pack_fclose(f);
6143 return true;
6144 }
6145
6146 bool save_subscreen(const char *path, ZCSubscreen const& savefrom)
6147 {
6148 //open the file
6149 PACKFILE *f=pack_fopen_password(path,F_WRITE, "");
6150
6151 if(!f)
6152 return false;
6153
6154 dword section_id=ID_SUBSCREEN;
6155 dword s_version=V_SUBSCREEN;
6156
6157 if(!p_mputl(section_id,f))
6158 {
6159 pack_fclose(f);
6160 return false;
6161 }
6162
6163 if(!p_iputw(s_version,f))
6164 {
6165 pack_fclose(f);
6166 return false;
6167 }
6168
6169 if(!write_deprecated_section_cversion(s_version,f))
6170 {
6171 pack_fclose(f);
6172 return false;
6173 }
6174
6175 if(savefrom.write(f))
6176 {
6177 pack_fclose(f);
6178 return false;
6179 }
6180
6181 pack_fclose(f);
6182 return true;
6183 }
6184
6185 bool load_subscreen(const char *path, ZCSubscreen& loadto)
6186 {
6187 //open the file
6188 PACKFILE *f=pack_fopen_password(path,F_READ, "");
6189
6190 if(!f)
6191 return false;
6192
6193 dword section_id;
6194 dword s_version;
6195
6196 if(!p_mgetl(&section_id,f))
6197 {
6198 pack_fclose(f);
6199 return false;
6200 }
6201
6202 if(section_id!=ID_SUBSCREEN)
6203 {
6204 pack_fclose(f);
6205 return false;
6206 }
6207
6208 if(!p_igetw(&s_version,f))
6209 {
6210 pack_fclose(f);
6211 return false;
6212 }
6213
6214 if (s_version > V_SUBSCREEN)
6215 return qe_version;
6216
6217 if(!read_deprecated_section_cversion(f))
6218 {
6219 pack_fclose(f);
6220 return false;
6221 }
6222
6223 if(s_version < 8)
6224 {
6225 subscreen_group g;
6226 memset(&g,0,sizeof(subscreen_group));
6227 if(read_one_old_subscreen(f,&g,s_version)!=0)
6228 {
6229 pack_fclose(f);
6230 return false;
6231 }
6232 if(g.ss_type != loadto.sub_type)
6233 {
6234 pack_fclose(f);
6235 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6236 subscr_names[g.ss_type], subscr_names[loadto.sub_type]));
6237 return false;
6238 }
6239 loadto.clear();
6240 if(g.objects[0].type != ssoNULL)
6241 loadto.load_old(g);
6242 }
6243 else
6244 {
6245 ZCSubscreen tmp = ZCSubscreen();
6246 if (tmp.read(f, s_version))
6247 {
6248 pack_fclose(f);
6249 return false;
6250 }
6251 if(tmp.sub_type != loadto.sub_type)
6252 {
6253 pack_fclose(f);
6254 displayinfo("Failure!",fmt::format("Found subscreen type '{}', expecting type '{}'",
6255 subscr_names[tmp.sub_type], subscr_names[loadto.sub_type]));
6256 return false;
6257 }
6258 loadto.clear();
6259 loadto = tmp;
6260 }
6261
6262 pack_fclose(f);
6263 return true;
6264 }
6265
6266 bool setMapCount2(int32_t c)
6267 {
6268 int32_t oldmapcount=map_count;
6269 int32_t cur_map=Map.getCurrMap();
6270
6271 bound(c,1,MAXMAPS);
6272 map_count=c;
6273
6274 try
6275 {
6276 TheMaps.resize(c*MAPSCRS);
6277 Map.force_refr_pointer();
6278 map_infos.resize(c);
6279 }
6280 catch(...)
6281 {
6282 jwin_alert("Error","Failed to change map count.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
6283 return false;
6284 }
6285
6286 bound(cur_map,0,c-1);
6287 if(map_count>oldmapcount)
6288 {
6289 for(int32_t mc=oldmapcount; mc<map_count; mc++)
6290 {
6291 // copy the default palette to the new maps
6292 map_infos[mc].autopalette = map_infos[cur_map].autopalette;
6293
6294 Map.setCurrMap(mc);
6295 for(int32_t ms=0; ms<MAPSCRS; ms++)
6296 Map.clearscr(ms);
6297 }
6298 Map.setCurrMap(cur_map);
6299 }
6300 else
6301 {
6302 Map.setCurrMap(cur_map);
6303 if(!layers_valid(Map.CurrScr()))
6304 fix_layers(Map.CurrScr(), false);
6305
6306 for(int32_t i=0; i<MAXDMAPS; i++)
6307 {
6308 if(DMaps[i].map>=map_count)
6309 {
6310 DMaps[i].map=map_count-1;
6311 }
6312 }
6313 }
6314
6315 return true;
6316 }
6317
6318 extern BITMAP *bmap;
6319
6320 static bool loading_file_new = false;
6321 int32_t init_quest(std::string tileset_path)
6322 {
6323 if (tileset_path.empty())
6324 tileset_path = DEFAULT_TILESET;
6325
6326 loading_file_new = true;
6327 load_quest(tileset_path.c_str());
6328 loading_file_new = false;
6329
6330 set_window_title("ZC Editor - Untitled Quest");
6331 zinit.last_map = 0;
6332 zinit.last_screen = 0;
6333
6334 if(bmap != NULL)
6335 {
6336 destroy_bitmap(bmap);
6337 bmap=NULL;
6338 }
6339
6340 return 0;
6341 }
6342
6343 void set_questpwd(std::string_view pwd, bool use_keyfile)
6344 {
6345 header.use_keyfile=use_keyfile;
6346
6347 // string_view actually has some quirks that make it less than ideal here.
6348 // It'd probably be best to replace it, but this works for now.
6349 memset(header.password, 0, 256);
6350 strcpy(header.password, pwd.data());
6351 header.dirty_password=true;
6352
6353 cvs_MD5Context ctx;
6354 cvs_MD5Init(&ctx);
6355 cvs_MD5Update(&ctx, (const uint8_t*)header.password, strlen(header.password));
6356 cvs_MD5Final(header.pwd_hash, &ctx);
6357 }
6358
6359
6360 bool is_null_pwd_hash(uint8_t *pwd_hash)
6361 {
6362 cvs_MD5Context ctx;
6363 uint8_t md5sum[16];
6364 char pwd[2]="";
6365
6366 cvs_MD5Init(&ctx);
6367 cvs_MD5Update(&ctx, (const uint8_t*)pwd, (unsigned)strlen(pwd));
6368 cvs_MD5Final(md5sum, &ctx);
6369
6370 return (memcmp(md5sum,pwd_hash,16)==0);
6371 }
6372
6373 static DIALOG pwd_dlg[] =
6374 {
6375 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
6376 { jwin_win_proc, 0, 0, 224+22+1, 88+10+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Requires Authorization", NULL, NULL },
6377 { jwin_text_proc, 16, 28, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "File name:", NULL, NULL },
6378 // 2 (filename)
6379 { jwin_text_proc, 72, 28, 128, 8, vc(11), vc(1), 0, 0, 24, 0, NULL, NULL, NULL },
6380 { jwin_text_proc, 16, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, (void *) "Challenge:", NULL, NULL },
6381 // 4 (challenge hash)
6382 { jwin_text_proc, 72, 38, 0, 8, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6383 { jwin_text_proc, 16, 42+10, 96, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Password:", NULL, NULL },
6384 // 6 (password)
6385 { jwin_edit_proc, 72, 38+10, 120+39, 16, vc(12), vc(1), 0, 0, 255, 0, NULL, NULL, NULL },
6386 { jwin_button_proc, 42, 62+10, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6387 { jwin_button_proc, 122, 62+10, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6388 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6389 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6390 };
6391
6392 int32_t reverse_string(char* str)
6393 {
6394
6395 if(NULL==str)
6396 {
6397 return -1; //no string
6398 }
6399
6400 int32_t l=(int32_t)strlen(str)-1; //get the string length
6401
6402 if(1==l)
6403 {
6404 return 1;
6405 }
6406
6407 char c;
6408
6409 for(int32_t x=0; x < l; x++,l--)
6410 {
6411 c = str[x];
6412 str[x] = str[l];
6413 str[l] = c;
6414 }
6415
6416 return 0;
6417 }
6418
6419 #ifdef __GNUC__
6420 #pragma GCC diagnostic push
6421 #pragma GCC diagnostic ignored "-Wunreachable-code"
6422 #endif
6423
6424 11 int32_t quest_access(const char *filename, zquestheader *hdr)
6425 {
6426
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (is_headless())
6427 11 return 1;
6428
6429 #ifdef __EMSCRIPTEN__
6430 return 1;
6431 #endif
6432
6433 //Protection against compiling a release version with password protection off.
6434 static bool passguard = false;
6435
6436 #if ( !(defined _DEBUG) || (defined _RELEASE || defined NDEBUG || defined _NDEBUG) )
6437 #define MUST_HAVE_PASSWORD
6438 passguard = true;
6439 #endif
6440
6441 #if ( !(defined MUST_HAVE_PASSWORD) || defined _NPASS )
6442 #if (defined _MSC_VER || defined _NPASS)
6443 return 1;
6444 #endif
6445 #endif
6446 if(devpwd()) return 1;
6447
6448 char hash_string[33];
6449
6450 if((get_debug() && (!(CHECK_CTRL_CMD))) || is_null_pwd_hash(hdr->pwd_hash))
6451 {
6452 return 1;
6453 }
6454
6455 if(check_keyfiles(filename, {KEYFILE_MASTER,KEYFILE_ZPWD}, hdr))
6456 return true;
6457
6458 pwd_dlg[0].dp2=get_zc_font(font_lfont);
6459 pwd_dlg[2].dp=get_filename(filename);
6460 cvs_MD5Context ctx;
6461 uint8_t md5sum[16]={0};
6462 char response[33]="";
6463 char prompt[256]="";
6464
6465 memcpy(md5sum, hdr->pwd_hash, 16);
6466
6467 for(int32_t i=0; i<300; ++i)
6468 {
6469 for(int32_t j=0; j<16; ++j)
6470 {
6471 sprintf(response+j*2, "%02x", md5sum[j]);
6472 }
6473
6474 if(i&1)
6475 {
6476 reverse_string(response);
6477 }
6478
6479 if(i==149)
6480 {
6481 strcpy(hash_string, response);
6482 }
6483
6484 cvs_MD5Init(&ctx);
6485 cvs_MD5Update(&ctx, (const uint8_t*)response, (unsigned)strlen(response));
6486 cvs_MD5Final(md5sum, &ctx);
6487 }
6488
6489 pwd_dlg[4].dp=hash_string;
6490
6491 if(get_debug() && (CHECK_CTRL_CMD)) //...what is this doing?
6492 {
6493 sprintf(prompt,"%s",response);
6494 }
6495
6496 pwd_dlg[6].dp=prompt;
6497
6498 large_dialog(pwd_dlg);
6499
6500 int32_t cancel = do_zqdialog(pwd_dlg,6);
6501
6502 if(cancel == 8)
6503 return 2;
6504
6505 bool ret=check_questpwd(hdr, prompt);
6506
6507 if(!ret)
6508 {
6509 ret=(strcmp(response,prompt)==0);
6510 }
6511 return ret ? 1 : 0;
6512 11 }
6513
6514 void set_rules(byte* newrules);
6515 11 void popup_bugfix_dlg(const char* cfg, byte* dest_qrs)
6516 {
6517 11 bool dont_show_again = zc_get_config("zquest",cfg,0);
6518
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 11 times.
11 if(!dont_show_again && hasCompatRulesEnabled())
6519 {
6520
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
33 AlertDialog("Apply New Bugfixes",
6521
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 "New bugfixes found that can be applied to this quest!"
6522 "\nWould you like to apply them?"
6523 "\n(Applies 'Bugfix' rule template, un-checking compat rules)",
6524 11 [&](bool ret,bool dsa)
6525 {
6526 if(ret)
6527 {
6528 applyRuleTemplate(ruletemplateFixCompat,dest_qrs);
6529 }
6530 if(dsa)
6531 {
6532 zc_set_config("zquest",cfg,1);
6533 }
6534 },
6535
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 "Yes","No",
6536 0,false, //timeout - none
6537 true //"Don't show this again"
6538
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 ).show();
6539 11 }
6540 11 }
6541
6542 #ifdef __GNUC__
6543 #pragma GCC diagnostic pop
6544 #endif
6545
6546 11 int32_t load_quest(const char *filename, bool show_progress)
6547 {
6548 char buf[2048];
6549 byte skip_flags[4];
6550
6551 11 dword tileset_flags = 0;
6552
2/2
✓ Branch 0 taken 44 times.
✓ Branch 1 taken 11 times.
55 for(int32_t i=0; i<4; ++i)
6553 {
6554 44 skip_flags[i]=0;
6555 44 }
6556
2/2
✓ Branch 0 taken 7634 times.
✓ Branch 1 taken 11 times.
7645 for(int32_t i=0; i<qr_MAX; i++)
6557 7634 set_qr(i,0);
6558 11 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,show_progress,skip_flags,1,true,0,tileset_flags);
6559
6560
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(ret!=qe_OK)
6561 {
6562 init_quest(DEFAULT_TILESET);
6563 }
6564 else
6565 {
6566 11 int32_t accessret = quest_access(filename, &header);
6567
6568
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(accessret != 1)
6569 {
6570 init_quest(DEFAULT_TILESET);
6571
6572 if(accessret == 0)
6573 ret=qe_pwd;
6574 else
6575 ret=qe_cancel;
6576 }
6577 else
6578 {
6579 11 Map.clear();
6580 11 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6581 11 Map.setCurrScr(zinit.last_screen);
6582
6583
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 std::string qst_cfg_header = qst_cfg_header_from_path(filename);
6584
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 Map.setViewSize(zc_get_config(qst_cfg_header.c_str(), "zoom_num_screens", 1));
6585
6586 extern int32_t current_mappage;
6587 11 current_mappage = 0;
6588 11 bool found_default = false;
6589
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 83 times.
92 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6590 {
6591 83 auto &pg = map_page[q];
6592
4/4
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 2 times.
83 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6593 {
6594 2 current_mappage = q;
6595 2 break;
6596 }
6597
4/8
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 72 times.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 9 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
81 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6598 72 continue;
6599 else
6600 {
6601 9 current_mappage = q;
6602 9 found_default = true;
6603 }
6604 9 }
6605
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh(rALL);
6606
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 refresh_pal();
6607
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 set_rules(quest_rules);
6608 11 saved = true;
6609
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
11 if(!(loading_file_new && zc_get_config("zquest","auto_filenew_bugfixes",1)))
6610
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 popup_bugfix_dlg("dsa_compatrule",nullptr);
6611
6612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if(bmap != NULL)
6613 {
6614 destroy_bitmap(bmap);
6615 bmap=NULL;
6616 }
6617
6618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (show_progress)
6619 {
6620 sprintf(buf,"ZC Editor - [%s]", get_filename(filename));
6621 set_window_title(buf);
6622 }
6623 11 }
6624 }
6625
6626 11 Map.ClearCommandHistory();
6627
6628
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!is_headless())
6629 {
6630 void load_size_poses();
6631 load_size_poses();
6632 }
6633
6634 11 return ret;
6635 }
6636
6637 int32_t load_tileset(const char *filename, dword tsetflags)
6638 {
6639 byte skip_flags[4];
6640
6641 for(int32_t i=0; i<4; ++i)
6642 skip_flags[i]=0;
6643 for(int32_t i=0; i<qr_MAX; i++)
6644 set_qr(i,0);
6645 int32_t ret=loadquest(filename,&header,&QMisc,customtunes,true,skip_flags,1,true,0,tsetflags);
6646
6647 if(ret!=qe_OK)
6648 init_quest(DEFAULT_TILESET);
6649 else
6650 {
6651 if(tsetflags & TILESET_BUGFIX)
6652 applyRuleTemplate(ruletemplateFixCompat);
6653 if(tsetflags & TILESET_SCR_BUGFIX)
6654 applyRuleTemplate(ruletemplateFixZSCompat);
6655
6656 int32_t accessret = quest_access(filename, &header);
6657
6658 if(accessret != 1)
6659 {
6660 init_quest(DEFAULT_TILESET);
6661
6662 if(accessret == 0)
6663 ret=qe_pwd;
6664 else
6665 ret=qe_cancel;
6666 }
6667 else
6668 {
6669 Map.clear();
6670 Map.setCurrMap(vbound(zinit.last_map,0,map_count-1));
6671 Map.setCurrScr(zinit.last_screen);
6672 extern int32_t current_mappage;
6673 current_mappage = 0;
6674 bool found_default = false;
6675 for(int q = 0; q < MAX_MAPPAGE_BTNS; ++q)
6676 {
6677 auto &pg = map_page[q];
6678 if(pg.map == Map.getCurrMap() && pg.screen == Map.getCurrScr())
6679 {
6680 current_mappage = q;
6681 break;
6682 }
6683 else if(found_default || pg.map > 1 || (pg.map == 1 && pg.screen > 0))
6684 continue;
6685 else
6686 {
6687 current_mappage = q;
6688 found_default = true;
6689 }
6690 }
6691 refresh(rALL);
6692 refresh_pal();
6693 set_rules(quest_rules);
6694
6695 if(bmap != NULL)
6696 {
6697 destroy_bitmap(bmap);
6698 bmap=NULL;
6699 }
6700
6701 set_window_title("ZC Editor - Untitled Quest");
6702 first_save = saved = false;
6703 memset(filepath,0,255);
6704 memset(temppath,0,255);
6705 }
6706 }
6707
6708 Map.ClearCommandHistory();
6709
6710 return ret;
6711 }
6712
6713 272730 int32_t write_weap_data(weapon_data const& data, PACKFILE* f)
6714 {
6715
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if(!p_iputw(V_WEAP_DATA,f))
6716 new_return(1);
6717
6718
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.flags, f))
6719 new_return(2);
6720
6721
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.moveflags, f))
6722 new_return(3);
6723
6724
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.wflags, f))
6725 new_return(4);
6726
6727
2/2
✓ Branch 0 taken 1363650 times.
✓ Branch 1 taken 272730 times.
1636380 for (int32_t q = 0; q < WPNSPR_MAX; ++q)
6728 {
6729
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.burnsprs[q], f))
6730 new_return(5);
6731
1/2
✓ Branch 0 taken 1363650 times.
✗ Branch 1 not taken.
1363650 if (!p_putc(data.light_rads[q], f))
6732 new_return(6);
6733 1363650 }
6734
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.glow_shape, f))
6735 new_return(7);
6736
6737
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.override_flags, f))
6738 new_return(8);
6739
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tilew, f))
6740 new_return(9);
6741
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.tileh, f))
6742 new_return(10);
6743
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxsz, f))
6744 new_return(11);
6745
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hysz, f))
6746 new_return(12);
6747
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hzsz, f))
6748 new_return(13);
6749
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hxofs, f))
6750 new_return(14);
6751
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.hyofs, f))
6752 new_return(15);
6753
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.xofs, f))
6754 new_return(16);
6755
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.yofs, f))
6756 new_return(17);
6757
6758
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.step, f))
6759 new_return(18);
6760
6761
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.unblockable, f))
6762 new_return(19);
6763
6764
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputl(data.timeout, f))
6765 new_return(20);
6766
6767
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.imitate_weapon, f))
6768 new_return(21);
6769
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.default_defense, f))
6770 new_return(22);
6771
6772
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_level, f))
6773 new_return(23);
6774
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_putc(data.lift_time, f))
6775 new_return(24);
6776
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputzf(data.lift_height, f))
6777 new_return(25);
6778
6779
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.script, f))
6780 new_return(26);
6781
2/2
✓ Branch 0 taken 2181840 times.
✓ Branch 1 taken 272730 times.
2454570 for(uint q = 0; q < 8; ++q)
6782
1/2
✓ Branch 0 taken 2181840 times.
✗ Branch 1 not taken.
2181840 if(!p_iputl(data.initd[q], f))
6783 new_return(27);
6784
1/2
✓ Branch 0 taken 272730 times.
✗ Branch 1 not taken.
272730 if (!p_iputw(data.pierce_count, f))
6785 new_return(28);
6786 272730 return 0;
6787 }
6788
6789 130 bool write_midi(MIDI *m,PACKFILE *f)
6790 {
6791 int32_t c;
6792
6793
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 130 times.
130 if(!p_mputw(m->divisions,f)) return false;
6794
6795
2/2
✓ Branch 0 taken 4160 times.
✓ Branch 1 taken 130 times.
4290 for(c=0; c<MIDI_TRACKS; c++)
6796 {
6797
1/2
✓ Branch 0 taken 4160 times.
✗ Branch 1 not taken.
4160 if(!p_mputl(m->track[c].len,f)) return false;
6798
6799
2/2
✓ Branch 0 taken 2896 times.
✓ Branch 1 taken 1264 times.
4160 if(m->track[c].len > 0)
6800 {
6801
1/2
✓ Branch 0 taken 1264 times.
✗ Branch 1 not taken.
1264 if(!pfwrite(m->track[c].data,m->track[c].len,f))
6802 return false;
6803 1264 }
6804 4160 }
6805
6806 130 return true;
6807 130 }
6808
6809 9 int32_t writeheader(PACKFILE *f, zquestheader *Header)
6810 {
6811 9 dword section_id=ID_HEADER;
6812 9 dword section_version=V_HEADER;
6813 9 dword section_size=0;
6814
6815 //file header string
6816
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!pfwrite(Header->id_str,sizeof(Header->id_str),f))
6817 {
6818 new_return(1);
6819 }
6820
6821 //section id
6822
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
6823 {
6824 new_return(2);
6825 }
6826
6827 //section version info
6828
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
6829 {
6830 new_return(3);
6831 }
6832
6833
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
6834 {
6835 new_return(4);
6836 }
6837
6838
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
6839 {
6840 18 fake_pack_writing=(writecycle==0);
6841
6842 //section size
6843
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
6844 {
6845 new_return(5);
6846 }
6847
6848 18 writesize=0;
6849
6850 //finally... section data
6851
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->zelda_version,f))
6852 {
6853 new_return(6);
6854 }
6855
6856
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->build,f))
6857 {
6858 new_return(7);
6859 }
6860
6861
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->pwd_hash,sizeof(Header->pwd_hash),f))
6862 {
6863 new_return(8);
6864 }
6865
6866
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(Header->internal,f))
6867 {
6868 new_return(10);
6869 }
6870
6871
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->quest_number,f))
6872 {
6873 new_return(11);
6874 }
6875
6876
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->version,16,f))
6877 {
6878 new_return(12);
6879 }
6880
6881
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->minver,16,f))
6882 {
6883 new_return(13);
6884 }
6885
6886
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->title,sizeof(Header->title),f))
6887 {
6888 new_return(14);
6889 }
6890
6891
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->author,sizeof(Header->author),f))
6892 {
6893 new_return(15);
6894 }
6895
6896
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->use_keyfile,f))
6897 {
6898 new_return(16);
6899 }
6900
6901
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->data_flags,sizeof(Header->data_flags),f))
6902 {
6903 new_return(17);
6904 }
6905
6906
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(Header->templatepath,sizeof(Header->templatepath),f))
6907 {
6908 new_return(19);
6909 }
6910
6911
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(0,f)) //why are we doing this?
6912 //this is for map count, it seems. -Z
6913 {
6914 new_return(20);
6915 }
6916
6917 18 auto version = getVersion();
6918
6919
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.major,f))
6920 {
6921 new_return(21);
6922 }
6923
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.minor,f))
6924 {
6925 new_return(22);
6926 }
6927
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(version.patch,f))
6928 {
6929 new_return(23);
6930 }
6931 // Fourth component is deprecated.
6932
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6933 {
6934 new_return(24);
6935 }
6936
6937 // Numerous prerelease stages is deprecated.
6938
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6939 {
6940 new_return(25);
6941 }
6942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6943 {
6944 new_return(26);
6945 }
6946
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6947 {
6948 new_return(27);
6949 }
6950
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(0,f))
6951 {
6952 new_return(28);
6953 }
6954
6955
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(BUILDTM_YEAR,f))
6956 {
6957 new_return(29);
6958 }
6959
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MONTH,f))
6960 {
6961 new_return(30);
6962 }
6963
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_DAY,f))
6964 {
6965 new_return(31);
6966 }
6967
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_HOUR,f))
6968 {
6969 new_return(32);
6970 }
6971
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(BUILDTM_MINUTE,f))
6972 {
6973 new_return(33);
6974 }
6975
6976 // This is no longer set to anything.
6977 const char* tempsig[256];
6978 18 memset(tempsig, 0, 256);
6979
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempsig,256,f))
6980 {
6981 new_return(34);
6982 }
6983
6984 char tempcompilersig[256];
6985 18 memset(tempcompilersig, 0, 256);
6986 18 strcpy(tempcompilersig, COMPILER_NAME);
6987
6988
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilersig,256,f))
6989 {
6990 new_return(35);
6991 }
6992
6993 char tempcompilerversion[256];
6994 18 memset(tempcompilerversion, 0, 256);
6995 #ifdef _MSC_VER
6996 zc_itoa(_MSC_VER,tempcompilerversion,10);
6997 #else
6998 18 strcpy(tempcompilerversion, COMPILER_VERSION);
6999 #endif
7000
7001
7002
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempcompilerversion,256,f))
7003 {
7004 new_return(36);
7005 }
7006
7007
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite("ZQuest Classic",1024,f))
7008 {
7009 new_return(37);
7010 }
7011
7012 // V_ZC_COMPILERSIG - a deprecated version field.
7013
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(1,f))
7014 {
7015 new_return(38);
7016 }
7017 #ifdef _MSC_VER
7018 if(!p_iputl((_MSC_VER / 100),f))
7019 {
7020 new_return(39);
7021 }
7022 #else
7023
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FIRST,f))
7024 {
7025 new_return(39);
7026 }
7027 #endif
7028
7029
7030
7031 #ifdef _MSC_VER
7032 if(!p_iputl((_MSC_VER % 100),f))
7033 {
7034 new_return(41);
7035 }
7036 #else
7037
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_SECOND,f))
7038 {
7039 new_return(41);
7040 }
7041 #endif
7042
7043 #ifdef _MSC_VER
7044 # if _MSC_VER >= 1400
7045 if(!p_iputl((_MSC_FULL_VER % 100000),f))
7046 {
7047 new_return(40);
7048 }
7049 # else
7050 if(!p_iputl((_MSC_FULL_VER % 10000),f))
7051 {
7052 new_return(40);
7053 }
7054 #endif
7055 #else
7056
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_THIRD,f))
7057 {
7058 new_return(40);
7059 }
7060 #endif
7061
7062 #ifdef _MSC_VER
7063 if(!p_iputl((_MSC_BUILD),f))
7064 {
7065 new_return(42);
7066 }
7067 #else
7068
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(COMPILER_V_FOURTH,f))
7069 {
7070 new_return(42);
7071 }
7072 #endif
7073
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(0,f)) //was V_ZC_DEVSIG, no longer used
7074 {
7075 new_return(43);
7076 }
7077
7078 // Modules were removed (replaced by zinfo).
7079 char tempmodulename[1024];
7080 18 memset(tempmodulename, 0, 1024);
7081
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempmodulename,1024,f))
7082 {
7083 new_return(44);
7084 }
7085
7086 char tempdate[256];
7087 18 memset(tempdate, 0, 256);
7088 18 strcpy(tempdate, __DATE__);
7089
7090
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&tempdate,256,f))
7091 {
7092 new_return(45);
7093 }
7094 char temptime[256];
7095 18 memset(temptime, 0, 256);
7096 18 strcpy(temptime, __TIME__);
7097
7098
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptime,256,f))
7099 {
7100 new_return(46);
7101 }
7102
7103
7104 char temptimezone[6];
7105 18 memset(temptimezone, 0, 6);
7106 18 strcpy(temptimezone, __TIMEZONE__);
7107
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&temptimezone,6,f))
7108 {
7109 new_return(47);
7110 }
7111
7112
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->external_zinfo ? 1 : 0, f))
7113 {
7114 new_return(48);
7115 }
7116
7117
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(isStableRelease() ? 0 : 1, f))
7118 {
7119 new_return(49);
7120 }
7121
7122
3/6
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
18 if(!p_putcstr(version.version_string, f))
7123 {
7124 new_return(50);
7125 }
7126
7127
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7128 {
7129 9 section_size=writesize;
7130 9 }
7131 18 }
7132
7133
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7134 {
7135 char ebuf[80];
7136 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7137 jwin_alert("Error: writeheader()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7138 }
7139
7140 9 new_return(0);
7141 }
7142
7143 9 int32_t writerules(PACKFILE *f, zquestheader *Header)
7144 {
7145 //these are here to bypass compiler warnings about unused arguments
7146 9 Header=Header;
7147
7148 9 dword section_id=ID_RULES;
7149 9 dword section_version=V_RULES;
7150 9 dword section_size=0;
7151
7152 //section id
7153
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7154 {
7155 new_return(1);
7156 }
7157
7158 //section version info
7159
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7160 {
7161 new_return(2);
7162 }
7163
7164
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
7165 {
7166 new_return(3);
7167 }
7168
7169
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!p_iputl(V_COMPATRULE,f))
7170 {
7171 new_return(6);
7172 }
7173
7174
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7175 {
7176 18 fake_pack_writing=(writecycle==0);
7177
7178 //section size
7179
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7180 {
7181 new_return(4);
7182 }
7183
7184 18 writesize=0;
7185
7186 //finally... section data
7187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(quest_rules,QUESTRULES_NEW_SIZE,f))
7188 {
7189 new_return(5);
7190 }
7191
7192
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7193 {
7194 9 section_size=writesize;
7195 9 }
7196 18 }
7197
7198
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7199 {
7200 char ebuf[80];
7201 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7202 jwin_alert("Error: writerules()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7203 }
7204
7205 9 new_return(0);
7206 }
7207
7208
7209 9 int32_t writedoorcombosets(PACKFILE *f, zquestheader *Header)
7210 {
7211 //these are here to bypass compiler warnings about unused arguments
7212 9 Header=Header;
7213
7214 9 dword section_id=ID_DOORS;
7215 9 dword section_version=V_DOORS;
7216 9 dword section_size=0;
7217
7218 //section id
7219
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7220 {
7221 new_return(1);
7222 }
7223
7224 //section version info
7225
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7226 {
7227 new_return(2);
7228 }
7229
7230
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7231 {
7232 new_return(3);
7233 }
7234
7235
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7236 {
7237 18 fake_pack_writing=(writecycle==0);
7238
7239 //section size
7240
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7241 {
7242 new_return(4);
7243 }
7244
7245 18 writesize=0;
7246
7247 //finally... section data
7248
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(door_combo_set_count,f))
7249 {
7250 new_return(5);
7251 }
7252
7253
2/2
✓ Branch 0 taken 320 times.
✓ Branch 1 taken 18 times.
338 for(int32_t i=0; i<door_combo_set_count; i++)
7254 {
7255 //name
7256 char name[21];
7257 320 memset(name, 21, (char)0);
7258 320 strcpy(name, DoorComboSetNames[i].c_str());
7259
1/2
✓ Branch 0 taken 320 times.
✗ Branch 1 not taken.
320 if(!pfwrite(name,sizeof(name),f))
7260 {
7261 new_return(6);
7262 }
7263
7264 //up door
7265
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7266 {
7267
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7268 {
7269
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_u[j][k],f))
7270 {
7271 new_return(7);
7272 }
7273 11520 }
7274 2880 }
7275
7276
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7277 {
7278
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7279 {
7280
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_u[j][k],f))
7281 {
7282 new_return(8);
7283 }
7284 11520 }
7285 2880 }
7286
7287 //down door
7288
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7289 {
7290
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7291 {
7292
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_iputw(DoorComboSets[i].doorcombo_d[j][k],f))
7293 {
7294 new_return(9);
7295 }
7296 11520 }
7297 2880 }
7298
7299
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7300 {
7301
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 11520 times.
14400 for(int32_t k=0; k<4; k++)
7302 {
7303
1/2
✓ Branch 0 taken 11520 times.
✗ Branch 1 not taken.
11520 if(!p_putc(DoorComboSets[i].doorcset_d[j][k],f))
7304 {
7305 new_return(10);
7306 }
7307 11520 }
7308 2880 }
7309
7310
7311 //left door
7312
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7313 {
7314
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7315 {
7316
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_l[j][k],f))
7317
7318 {
7319 new_return(11);
7320 }
7321 17280 }
7322 2880 }
7323
7324
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7325 {
7326
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7327 {
7328
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_l[j][k],f))
7329 {
7330 new_return(12);
7331 }
7332 17280 }
7333 2880 }
7334
7335 //right door
7336
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7337 {
7338
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7339 {
7340
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_iputw(DoorComboSets[i].doorcombo_r[j][k],f))
7341 {
7342 new_return(13);
7343 }
7344 17280 }
7345 2880 }
7346
7347
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 320 times.
3200 for(int32_t j=0; j<9; j++)
7348 {
7349
2/2
✓ Branch 0 taken 2880 times.
✓ Branch 1 taken 17280 times.
20160 for(int32_t k=0; k<6; k++)
7350 {
7351
1/2
✓ Branch 0 taken 17280 times.
✗ Branch 1 not taken.
17280 if(!p_putc(DoorComboSets[i].doorcset_r[j][k],f))
7352 {
7353 new_return(14);
7354 }
7355 17280 }
7356 2880 }
7357
7358
7359 //up bomb rubble
7360
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7361 {
7362
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_u[j],f))
7363 {
7364 new_return(15);
7365 }
7366 640 }
7367
7368
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7369 {
7370
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_u[j],f))
7371 {
7372 new_return(16);
7373 }
7374 640 }
7375
7376 //down bomb rubble
7377
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7378 {
7379
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_iputw(DoorComboSets[i].bombdoorcombo_d[j],f))
7380 {
7381 new_return(17);
7382 }
7383 640 }
7384
7385
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7386 {
7387
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].bombdoorcset_d[j],f))
7388 {
7389 new_return(18);
7390 }
7391 640 }
7392
7393 //left bomb rubble
7394
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7395 {
7396
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_l[j],f))
7397 {
7398 new_return(19);
7399 }
7400 960 }
7401
7402
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7403 {
7404
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_l[j],f))
7405 {
7406 new_return(20);
7407 }
7408 960 }
7409
7410 //right bomb rubble
7411
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7412 {
7413
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_iputw(DoorComboSets[i].bombdoorcombo_r[j],f))
7414 {
7415 new_return(21);
7416 }
7417 960 }
7418
7419
2/2
✓ Branch 0 taken 960 times.
✓ Branch 1 taken 320 times.
1280 for(int32_t j=0; j<3; j++)
7420 {
7421
1/2
✓ Branch 0 taken 960 times.
✗ Branch 1 not taken.
960 if(!p_putc(DoorComboSets[i].bombdoorcset_r[j],f))
7422 {
7423 new_return(22);
7424 }
7425 960 }
7426
7427 //walkthrough stuff
7428
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7429 {
7430
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_iputw(DoorComboSets[i].walkthroughcombo[j],f))
7431 {
7432 new_return(23);
7433 }
7434 1280 }
7435
7436
2/2
✓ Branch 0 taken 1280 times.
✓ Branch 1 taken 320 times.
1600 for(int32_t j=0; j<4; j++)
7437 {
7438
1/2
✓ Branch 0 taken 1280 times.
✗ Branch 1 not taken.
1280 if(!p_putc(DoorComboSets[i].walkthroughcset[j],f))
7439 {
7440 new_return(24);
7441 }
7442 1280 }
7443
7444 //flags
7445
2/2
✓ Branch 0 taken 640 times.
✓ Branch 1 taken 320 times.
960 for(int32_t j=0; j<2; j++)
7446 {
7447
1/2
✓ Branch 0 taken 640 times.
✗ Branch 1 not taken.
640 if(!p_putc(DoorComboSets[i].flags[j],f))
7448 {
7449 new_return(25);
7450 }
7451 640 }
7452 320 }
7453
7454
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7455 {
7456 9 section_size=writesize;
7457 9 }
7458 18 }
7459
7460
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7461 {
7462 char ebuf[80];
7463 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7464 jwin_alert("Error: writedoorcombosets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7465 }
7466
7467 9 new_return(0);
7468 }
7469
7470 9 int32_t writedmaps(PACKFILE *f, word version, word build, word start_dmap, word max_dmaps)
7471 {
7472 //these are here to bypass compiler warnings about unused arguments
7473 9 version=version;
7474 9 build=build;
7475
7476 9 word dmap_count=count_dmaps();
7477 9 dword section_id=ID_DMAPS;
7478 9 dword section_version=V_DMAPS;
7479 9 dword section_size=0;
7480
7481 //section id
7482
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7483 {
7484 new_return(1);
7485 }
7486
7487 //section version info
7488
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7489 {
7490 new_return(2);
7491 }
7492
7493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7494 {
7495 new_return(3);
7496 }
7497
7498
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7499 {
7500 18 fake_pack_writing=(writecycle==0);
7501
7502 //section size
7503
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7504 {
7505 new_return(4);
7506 }
7507
7508 18 writesize=0;
7509
7510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, max_dmaps);
7511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 dmap_count=zc_min(dmap_count, MAXDMAPS-start_dmap);
7512
7513 //finally... section data
7514
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(dmap_count,f))
7515 {
7516 new_return(5);
7517 }
7518
7519
7520
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=start_dmap; i<start_dmap+dmap_count; i++)
7521 {
7522 9216 DMaps[i].validate_subscreens();
7523
7524
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].map,f))
7525 {
7526 new_return(6);
7527 }
7528
7529
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].level,f))
7530 {
7531 new_return(7);
7532 }
7533
7534
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].xoff,f))
7535 {
7536 new_return(8);
7537 }
7538
7539
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].compass,f))
7540 {
7541 new_return(9);
7542 }
7543
7544
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].color,f))
7545 {
7546 new_return(10);
7547 }
7548
7549
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].midi,f))
7550 {
7551 new_return(11);
7552 }
7553
7554
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].cont,f))
7555 {
7556 new_return(12);
7557 }
7558
7559
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].type,f))
7560 {
7561 new_return(13);
7562 }
7563
7564
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t j=0; j<8; j++)
7565 {
7566
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(DMaps[i].grid[j],f))
7567 {
7568 new_return(14);
7569 }
7570 73728 }
7571
7572
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name)-1,f))
7573 {
7574 new_return(15);
7575 }
7576
7577
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putwstr(DMaps[i].title,f))
7578 {
7579 new_return(16);
7580 }
7581
7582
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro)-1,f))
7583 {
7584 new_return(17);
7585 }
7586
7587
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[0],f))
7588 {
7589 new_return(18);
7590 }
7591
7592
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[0],f))
7593 {
7594 new_return(19);
7595 }
7596
7597
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].minimap_tile[1],f))
7598 {
7599 new_return(20);
7600 }
7601
7602
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].minimap_cset[1],f))
7603 {
7604 new_return(21);
7605 }
7606
7607
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[0],f))
7608 {
7609 new_return(22);
7610 }
7611
7612
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[0],f))
7613 {
7614 new_return(23);
7615 }
7616
7617
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].largemap_tile[1],f))
7618 {
7619 new_return(24);
7620 }
7621
7622
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].largemap_cset[1],f))
7623 {
7624 new_return(25);
7625 }
7626
7627
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic)-1,f))
7628 {
7629 new_return(26);
7630 }
7631
7632
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].tmusictrack,f))
7633 {
7634 new_return(25);
7635 }
7636
7637
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].active_subscreen,f))
7638 {
7639 new_return(26);
7640 }
7641
7642
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].passive_subscreen,f))
7643 {
7644 new_return(27);
7645 }
7646
7647 byte disabled[32];
7648 9216 memset(disabled,0,32);
7649
7650
2/2
✓ Branch 0 taken 2359296 times.
✓ Branch 1 taken 9216 times.
2368512 for(int32_t j=0; j<MAXITEMS; j++)
7651 {
7652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2359296 times.
2359296 if(DMaps[i].disableditems[j])
7653 {
7654 disabled[j/8] |= (1 << (j%8));
7655 }
7656 2359296 }
7657
7658
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite(disabled,32,f))
7659 {
7660 new_return(28);
7661 }
7662
7663
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(DMaps[i].flags,f))
7664 {
7665 new_return(29);
7666 }
7667
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].sideview,f))
7668 {
7669 new_return(30);
7670 }
7671
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].script,f))
7672 {
7673 new_return(31);
7674 }
7675
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7676 {
7677
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].initD[q],f))
7678 {
7679 new_return(32);
7680 }
7681
7682 73728 }
7683
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
7684 {
7685
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
7686 {
7687
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if (!p_putc(DMaps[i].initD_label[q][w],f))
7688 {
7689 new_return(33);
7690 }
7691 4792320 }
7692 73728 }
7693
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].active_sub_script,f))
7694 {
7695 new_return(34);
7696 }
7697
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].passive_sub_script,f))
7698 {
7699 new_return(35);
7700 }
7701
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7702 {
7703
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].sub_initD[q],f))
7704 {
7705 new_return(36);
7706 }
7707 73728 }
7708
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7709 {
7710
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7711 {
7712
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
7713 {
7714 new_return(37);
7715 }
7716 4792320 }
7717 73728 }
7718
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].onmap_script,f))
7719 {
7720 new_return(38);
7721 }
7722
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7723 {
7724
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(DMaps[i].onmap_initD[q],f))
7725 {
7726 new_return(39);
7727 }
7728 73728 }
7729
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for(int32_t q = 0; q < 8; ++q)
7730 {
7731
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for(int32_t w = 0; w < 65; ++w)
7732 {
7733
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
7734 {
7735 new_return(40);
7736 }
7737 4792320 }
7738 73728 }
7739
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(DMaps[i].mirrorDMap,f))
7740 {
7741 new_return(41);
7742 }
7743
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
7744 {
7745 new_return(42);
7746 }
7747
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
7748 {
7749 new_return(43);
7750 }
7751
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
7752 {
7753 new_return(44);
7754 }
7755
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
7756 {
7757 new_return(45);
7758 }
7759
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(DMaps[i].overlay_subscreen, f))
7760 new_return(46);
7761
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(DMaps[i].intro_string_id, f))
7762 new_return(47);
7763
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (DMaps[i].flags & dmfCUSTOM_GRAVITY)
7764 {
7765 if (!p_iputzf(DMaps[i].dmap_gravity, f))
7766 new_return(48);
7767 if (!p_iputzf(DMaps[i].dmap_terminal_v, f))
7768 new_return(49);
7769 }
7770 9216 }
7771
7772
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7773 {
7774 9 section_size=writesize;
7775 9 }
7776 18 }
7777
7778
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7779 {
7780 char ebuf[80];
7781 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7782 jwin_alert("Error: writedmaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7783 }
7784
7785 9 new_return(0);
7786 }
7787
7788 9 int32_t writemisccolors(PACKFILE *f, zquestheader *Header)
7789 {
7790 //these are here to bypass compiler warnings about unused arguments
7791 9 Header=Header;
7792
7793 9 dword section_id=ID_COLORS;
7794 9 dword section_version=V_COLORS;
7795 9 dword section_size = 0;
7796
7797 //section id
7798
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
7799 {
7800 new_return(1);
7801 }
7802
7803
7804 //section version info
7805
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
7806 {
7807 new_return(2);
7808 }
7809
7810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
7811 {
7812 new_return(3);
7813 }
7814
7815
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
7816 {
7817 18 fake_pack_writing=(writecycle==0);
7818
7819 //section size
7820
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
7821 {
7822 new_return(4);
7823 }
7824
7825 18 writesize=0;
7826
7827
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.text,f))
7828 {
7829 new_return(5);
7830 }
7831
7832
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.caption,f))
7833 {
7834 new_return(6);
7835 }
7836
7837
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overw_bg,f))
7838 {
7839 new_return(7);
7840 }
7841
7842
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_bg,f))
7843 {
7844 new_return(8);
7845 }
7846
7847
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dngn_fg,f))
7848 {
7849 new_return(9);
7850 }
7851
7852
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.cave_fg,f))
7853 {
7854 new_return(10);
7855 }
7856
7857
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_dk,f))
7858 {
7859 new_return(11);
7860 }
7861
7862
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bs_goal,f))
7863 {
7864 new_return(12);
7865 }
7866
7867
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_lt,f))
7868 {
7869 new_return(13);
7870 }
7871
7872
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.compass_dk,f))
7873 {
7874 new_return(14);
7875 }
7876
7877
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_bg,f))
7878 {
7879 new_return(15);
7880 }
7881
7882
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_color,f))
7883 {
7884 new_return(16);
7885 }
7886
7887
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.hero_dot,f))
7888 {
7889 new_return(17);
7890 }
7891
7892
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_bg,f))
7893 {
7894 new_return(18);
7895 }
7896
7897
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.bmap_fg,f))
7898 {
7899 new_return(19);
7900 }
7901
7902
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triforce_cset,f))
7903 {
7904 new_return(20);
7905 }
7906
7907
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.triframe_cset,f))
7908 {
7909 new_return(21);
7910 }
7911
7912
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.overworld_map_cset,f))
7913 {
7914 new_return(22);
7915 }
7916
7917
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.dungeon_map_cset,f))
7918 {
7919 new_return(23);
7920 }
7921
7922
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.blueframe_cset,f))
7923 {
7924 new_return(24);
7925 }
7926
7927
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.HCpieces_cset,f))
7928 {
7929 new_return(31);
7930 }
7931
7932
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.subscr_shadow,f))
7933 {
7934 new_return(32);
7935 }
7936
7937
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(QMisc.colors.msgtext,f))
7938 {
7939 new_return(33);
7940 }
7941
7942
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triforce_tile,f))
7943 {
7944 new_return(34);
7945 }
7946
7947
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.triframe_tile,f))
7948 {
7949 new_return(35);
7950 }
7951
7952
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.overworld_map_tile,f))
7953 {
7954 new_return(36);
7955 }
7956
7957
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.dungeon_map_tile,f))
7958 {
7959 new_return(37);
7960 }
7961
7962
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.blueframe_tile,f))
7963 {
7964 new_return(38);
7965 }
7966
7967
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.colors.HCpieces_tile,f))
7968 {
7969 new_return(39);
7970 }
7971
7972
7973
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
7974 {
7975 9 section_size=writesize;
7976 9 }
7977 18 }
7978
7979
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
7980 {
7981 char ebuf[80];
7982 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
7983 jwin_alert("Error: writemisccolors()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
7984 }
7985
7986 9 new_return(0);
7987 }
7988
7989 9 int32_t writegameicons(PACKFILE *f, zquestheader *Header)
7990 {
7991 //these are here to bypass compiler warnings about unused arguments
7992 9 Header=Header;
7993
7994 9 dword section_id=ID_ICONS;
7995 9 dword section_version=V_ICONS;
7996 9 dword section_size = 0;
7997
7998 //section id
7999
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8000 {
8001 new_return(1);
8002 }
8003
8004 //section version info
8005
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8006 {
8007 new_return(2);
8008 }
8009
8010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8011 {
8012 new_return(3);
8013 }
8014
8015
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8016 {
8017 18 fake_pack_writing=(writecycle==0);
8018
8019 //section size
8020
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8021 {
8022 new_return(4);
8023 }
8024
8025 18 writesize=0;
8026
8027
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
8028 {
8029
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(QMisc.icons[i],f))
8030 {
8031 new_return(5);
8032 }
8033 72 }
8034
8035
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8036 {
8037 9 section_size=writesize;
8038 9 }
8039 18 }
8040
8041
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8042 {
8043 char ebuf[80];
8044 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8045 jwin_alert("Error: writegameicons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8046 }
8047
8048 9 new_return(0);
8049 }
8050
8051 9 int32_t writemisc(PACKFILE *f, zquestheader *Header)
8052 {
8053 //these are here to bypass compiler warnings about unused arguments
8054 9 Header=Header;
8055
8056 9 dword section_id=ID_MISC;
8057 9 dword section_version=V_MISC;
8058 9 word shops=count_shops(&QMisc);
8059 9 word infos=count_infos(&QMisc);
8060 9 word warprings=count_warprings(&QMisc);
8061 9 word triforces=8;
8062 9 dword section_size = 0;
8063
8064 //section id
8065
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8066 {
8067 new_return(1);
8068 }
8069
8070
8071 //section version info
8072
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8073 {
8074 new_return(2);
8075 }
8076
8077
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8078 {
8079 new_return(3);
8080 }
8081
8082
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8083 {
8084 18 fake_pack_writing=(writecycle==0);
8085
8086 //section size
8087
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8088 {
8089 new_return(4);
8090 }
8091
8092 18 writesize=0;
8093
8094 //shops
8095
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(shops,f))
8096 {
8097 new_return(5);
8098 }
8099
8100
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8101 {
8102
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.shop[i].name,sizeof(QMisc.shop[i].name)-1,f))
8103 {
8104 new_return(6);
8105 }
8106
8107
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8108 {
8109
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].item[j],f))
8110 {
8111 new_return(7);
8112 }
8113 480 }
8114
8115
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8116 {
8117
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].price[j],f))
8118 {
8119 new_return(8);
8120 }
8121 480 }
8122
8123
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8124 {
8125
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_putc(QMisc.shop[i].hasitem[j],f))
8126 {
8127 new_return(9);
8128 }
8129 480 }
8130 160 }
8131
8132 //infos
8133
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(infos,f))
8134 {
8135 new_return(10);
8136 }
8137
8138
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<infos; i++)
8139 {
8140
1/2
✓ Branch 0 taken 160 times.
✗ Branch 1 not taken.
160 if(!pfwrite(QMisc.info[i].name,sizeof(QMisc.info[i].name)-1,f))
8141 {
8142 new_return(11);
8143 }
8144
8145
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8146 {
8147
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].str[j],f))
8148 {
8149 new_return(12);
8150 }
8151 480 }
8152
8153
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8154 {
8155
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.info[i].price[j],f))
8156 {
8157 new_return(13);
8158 }
8159 480 }
8160 160 }
8161
8162 //warp rings
8163
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(warprings,f))
8164 {
8165 new_return(14);
8166 }
8167
8168
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 18 times.
226 for(int32_t i=0; i<warprings; i++)
8169 {
8170
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8171 {
8172
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_iputw(QMisc.warp[i].dmap[j],f))
8173 {
8174 new_return(15);
8175 }
8176 1872 }
8177
8178
2/2
✓ Branch 0 taken 1872 times.
✓ Branch 1 taken 208 times.
2080 for(int32_t j=0; j<9; j++)
8179 {
8180
1/2
✓ Branch 0 taken 1872 times.
✗ Branch 1 not taken.
1872 if(!p_putc(QMisc.warp[i].scr[j],f))
8181 {
8182 new_return(16);
8183 }
8184 1872 }
8185
8186
1/2
✓ Branch 0 taken 208 times.
✗ Branch 1 not taken.
208 if(!p_putc(QMisc.warp[i].size,f))
8187 {
8188 new_return(17);
8189 }
8190 208 }
8191
8192 //triforce pieces
8193
2/2
✓ Branch 0 taken 144 times.
✓ Branch 1 taken 18 times.
162 for(int32_t i=0; i<triforces; i++)
8194 {
8195
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(!p_putc(QMisc.triforce[i],f))
8196 {
8197 new_return(18);
8198 }
8199 144 }
8200
8201 //end string
8202
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(QMisc.endstring,f))
8203 {
8204 new_return(19);
8205 }
8206
8207 //V_MISC >= 8
8208
2/2
✓ Branch 0 taken 160 times.
✓ Branch 1 taken 18 times.
178 for(int32_t i=0; i<shops; i++)
8209 {
8210
2/2
✓ Branch 0 taken 480 times.
✓ Branch 1 taken 160 times.
640 for(int32_t j=0; j<3; j++)
8211 {
8212
1/2
✓ Branch 0 taken 480 times.
✗ Branch 1 not taken.
480 if(!p_iputw(QMisc.shop[i].str[j],f))
8213 {
8214 new_return(20);
8215 }
8216 480 }
8217 160 }
8218 //V_MISC >= 9
8219
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8220 {
8221
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_iputl(QMisc.questmisc[q],f))
8222 new_return(21);
8223 576 }
8224
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for ( int32_t q = 0; q < 32; q++ )
8225 {
8226
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 576 times.
74304 for ( int32_t j = 0; j < 128; j++ )
8227
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_putc(0,f))
8228 new_return(22);
8229 576 }
8230 //V_MISC >= 11
8231
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(QMisc.zscript_last_compiled_version,f))
8232 new_return(23);
8233
8234 //V_MISC >= 12
8235
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sprMAX; ++q)
8236 {
8237
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.sprites[q],f))
8238 new_return(24);
8239 4608 }
8240
8241 //V_MISC >= 13
8242
2/2
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 18 times.
1170 for(size_t q = 0; q < 64; ++q)
8243 {
8244 1152 bottletype* bt = &(QMisc.bottle_types[q]);
8245
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!pfwrite(bt->name, 32, f))
8246 new_return(25);
8247
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 1152 times.
4608 for(size_t j = 0; j < 3; ++j)
8248 {
8249
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_putc(bt->counter[j], f))
8250 new_return(25);
8251
1/2
✓ Branch 0 taken 3456 times.
✗ Branch 1 not taken.
3456 if (!p_iputw(bt->amount[j], f))
8252 new_return(25);
8253 3456 }
8254
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->flags, f))
8255 new_return(25);
8256
1/2
✓ Branch 0 taken 1152 times.
✗ Branch 1 not taken.
1152 if (!p_putc(bt->next_type, f))
8257 new_return(25);
8258 1152 }
8259
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(size_t q = 0; q < 256; ++q)
8260 {
8261 4608 bottleshoptype* bst = &(QMisc.bottle_shop_types[q]);
8262
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!pfwrite(bst->name, 32, f))
8263 new_return(26);
8264
2/2
✓ Branch 0 taken 13824 times.
✓ Branch 1 taken 4608 times.
18432 for(size_t j = 0; j < 3; ++j)
8265 {
8266
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->fill[j], f))
8267 new_return(26);
8268
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->comb[j], f))
8269 new_return(26);
8270
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_putc(bst->cset[j], f))
8271 new_return(26);
8272
1/2
✓ Branch 0 taken 13824 times.
✗ Branch 1 not taken.
13824 if (!p_iputw(bst->price[j], f))
8273 new_return(26);
8274
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13824 times.
13824 if (!p_iputw(bst->str[j], f))
8275 new_return(26);
8276 13824 }
8277 4608 }
8278
8279 //V_MISC >= 14
8280
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t q = 0; q < sfxMAX; ++q)
8281 {
8282
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(QMisc.miscsfx[q],f))
8283 new_return(27);
8284 4608 }
8285
8286
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8287 {
8288 9 section_size=writesize;
8289 9 }
8290 18 }
8291
8292
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8293 {
8294 char ebuf[80];
8295 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8296 jwin_alert("Error: writemisc()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8297 }
8298
8299 9 new_return(0);
8300 }
8301
8302 9 int32_t writeitems(PACKFILE *f, zquestheader *Header)
8303 {
8304 //these are here to bypass compiler warnings about unused arguments
8305 9 Header=Header;
8306
8307 9 dword section_id=ID_ITEMS;
8308 9 dword section_version=V_ITEMS;
8309 // dword section_size=0;
8310 9 dword section_size = 0;
8311
8312 //section id
8313
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8314 {
8315 new_return(1);
8316 }
8317
8318 //section version info
8319
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8320 {
8321 new_return(2);
8322 }
8323
8324
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
8325 {
8326 new_return(3);
8327 }
8328
8329
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8330 {
8331 18 fake_pack_writing=(writecycle==0);
8332
8333 //section size
8334
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8335 {
8336 new_return(4);
8337 }
8338
8339 18 writesize=0;
8340
8341 //finally... section data
8342
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXITEMS,f))
8343 {
8344 new_return(5);
8345 }
8346
8347
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8348 {
8349
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite(item_string[i], 64, f))
8350 {
8351 new_return(5);
8352 }
8353 4608 }
8354
8355
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXITEMS; i++)
8356 {
8357
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tile,f))
8358 {
8359 new_return(6);
8360 }
8361
8362
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].misc_flags,f))
8363 {
8364 new_return(7);
8365 }
8366
8367
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].csets,f))
8368 {
8369 new_return(8);
8370 }
8371
8372
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].frames,f))
8373 {
8374 new_return(9);
8375 }
8376
8377
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].speed,f))
8378 {
8379 new_return(10);
8380 }
8381
8382
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].delay,f))
8383 {
8384 new_return(11);
8385 }
8386
8387
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].ltm,f))
8388 {
8389 new_return(12);
8390 }
8391
8392
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].type,f))
8393 {
8394 new_return(13);
8395 }
8396
8397
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].level,f))
8398 {
8399 new_return(14);
8400 }
8401
8402
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].power,f))
8403 {
8404 new_return(14);
8405 }
8406
8407
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].flags,f))
8408 {
8409 new_return(15);
8410 }
8411
8412
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].script,f))
8413 {
8414 new_return(16);
8415 }
8416
8417
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].count,f))
8418 {
8419 new_return(17);
8420 }
8421
8422
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].amount,f))
8423 {
8424 new_return(18);
8425 }
8426
8427
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].collect_script,f))
8428 {
8429 new_return(19);
8430 }
8431
8432
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].setmax,f))
8433 {
8434 new_return(21);
8435 }
8436
8437
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].max,f))
8438 {
8439 new_return(22);
8440 }
8441
8442
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].playsound,f))
8443 {
8444 new_return(23);
8445 }
8446
8447
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for(int32_t j=0; j<8; j++)
8448 {
8449
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].initiald[j],f))
8450 {
8451 new_return(24);
8452 }
8453 36864 }
8454
8455
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(int32_t j=0; j<2; j++)
8456 {
8457
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8458 {
8459 new_return(25);
8460 }
8461 9216 }
8462
8463
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn,f))
8464 {
8465 new_return(26);
8466 }
8467
8468
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn2,f))
8469 {
8470 new_return(27);
8471 }
8472
8473
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn3,f))
8474 {
8475 new_return(28);
8476 }
8477
8478
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn4,f))
8479 {
8480 new_return(29);
8481 }
8482
8483
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn5,f))
8484 {
8485 new_return(30);
8486 }
8487
8488
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn6,f))
8489 {
8490 new_return(31);
8491 }
8492
8493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].wpn7,f))
8494 {
8495 new_return(32);
8496 }
8497
8498
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn8,f))
8499 {
8500 new_return(33);
8501 }
8502
8503
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn9,f))
8504 {
8505 new_return(34);
8506 }
8507
8508
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].wpn10,f))
8509 {
8510 new_return(35);
8511 }
8512
8513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(!p_putc(itemsbuf[i].pickup_hearts,f))
8514 {
8515 new_return(36);
8516 }
8517
8518
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc1,f))
8519 {
8520 new_return(37);
8521 }
8522
8523
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc2,f))
8524 {
8525 new_return(38);
8526 }
8527
8528
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8529 {
8530
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(itemsbuf[i].cost_amount[q],f))
8531 {
8532 new_return(39);
8533 }
8534 9216 }
8535
8536
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc3,f))
8537 {
8538 new_return(40);
8539 }
8540
8541
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc4,f))
8542 {
8543 new_return(41);
8544 }
8545
8546
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc5,f))
8547 {
8548 new_return(42);
8549 }
8550
8551
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc6,f))
8552 {
8553 new_return(43);
8554 }
8555
8556
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc7,f))
8557 {
8558 new_return(44);
8559 }
8560
8561
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc8,f))
8562 {
8563 new_return(45);
8564 }
8565
8566
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc9,f))
8567 {
8568 new_return(46);
8569 }
8570
8571
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].misc10,f))
8572 {
8573 new_return(47);
8574 }
8575
8576
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound,f))
8577 {
8578 new_return(48);
8579 }
8580
8581
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].usesound2,f))
8582 {
8583 new_return(48);
8584 }
8585
8586 //New itemdata vars -Z
8587 //! version 27
8588
8589
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weaprange,f))
8590 {
8591 new_return(51);
8592 }
8593
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].weapduration,f))
8594 {
8595 new_return(52);
8596 }
8597
2/2
✓ Branch 0 taken 46080 times.
✓ Branch 1 taken 4608 times.
50688 for ( int32_t q = 0; q < ITEM_MOVEMENT_PATTERNS; q++ ) {
8598
1/2
✓ Branch 0 taken 46080 times.
✗ Branch 1 not taken.
46080 if(!p_iputl(itemsbuf[i].weap_pattern[q],f))
8599 {
8600 new_return(53);
8601 }
8602 46080 }
8603 //version 28
8604
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].duplicates,f))
8605 {
8606 new_return(54);
8607 }
8608
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8609 {
8610
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8611 {
8612 new_return(56);
8613 }
8614 9216 }
8615
8616
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].drawlayer,f))
8617 {
8618 new_return(57);
8619 }
8620
8621
8622
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxofs,f))
8623 {
8624 new_return(58);
8625 }
8626
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hyofs,f))
8627 {
8628 new_return(59);
8629 }
8630
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hxsz,f))
8631 {
8632 new_return(60);
8633 }
8634
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hysz,f))
8635 {
8636 new_return(61);
8637 }
8638
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].hzsz,f))
8639 {
8640 new_return(62);
8641 }
8642
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].xofs,f))
8643 {
8644 new_return(63);
8645 }
8646
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].yofs,f))
8647 {
8648 new_return(64);
8649 }
8650
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].wpnsprite,f))
8651 {
8652 new_return(73);
8653 }
8654
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8655 {
8656
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(itemsbuf[i].magiccosttimer[q],f))
8657 {
8658 new_return(74);
8659 }
8660 9216 }
8661
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].overrideFLAGS,f))
8662 {
8663 new_return(75);
8664 }
8665
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tilew,f))
8666 {
8667 new_return(76);
8668 }
8669
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].tileh,f))
8670 {
8671 new_return(77);
8672 }
8673
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(itemsbuf[i].pickup,f))
8674 {
8675 new_return(81);
8676 }
8677
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pstring,f))
8678 {
8679 new_return(82);
8680 }
8681
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_string_flags,f))
8682 {
8683 new_return(83);
8684 }
8685
8686
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for(auto q = 0; q < 2; ++q)
8687 {
8688
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(itemsbuf[i].cost_counter[q],f))
8689 {
8690 new_return(84);
8691 }
8692 9216 }
8693
8694 //InitD[] labels
8695
2/2
✓ Branch 0 taken 36864 times.
✓ Branch 1 taken 4608 times.
41472 for ( int32_t q = 0; q < 8; q++ )
8696 {
8697
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8698 {
8699
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].initD_label[q][w],f))
8700 {
8701 new_return(85);
8702 }
8703 2396160 }
8704
2/2
✓ Branch 0 taken 2396160 times.
✓ Branch 1 taken 36864 times.
2433024 for ( int32_t w = 0; w < 65; w++ )
8705 {
8706
1/2
✓ Branch 0 taken 2396160 times.
✗ Branch 1 not taken.
2396160 if(!p_putc(itemsbuf[i].sprite_initD_label[q][w],f))
8707 {
8708 new_return(87);
8709 }
8710 2396160 }
8711
1/2
✓ Branch 0 taken 36864 times.
✗ Branch 1 not taken.
36864 if(!p_iputl(itemsbuf[i].sprite_initiald[q],f))
8712 {
8713 new_return(88);
8714 }
8715 36864 }
8716
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 4608 times.
13824 for ( int32_t q = 0; q < 2; q++ )
8717 {
8718
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(0,f))
8719 {
8720 new_return(89);
8721 }
8722
8723 9216 }
8724
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(itemsbuf[i].sprite_script,f))
8725 {
8726 new_return(90);
8727 }
8728
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(itemsbuf[i].pickupflag,f))
8729 {
8730 new_return(91);
8731 }
8732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 std::string dispname(itemsbuf[i].display_name);
8733
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(!p_putcstr(dispname,f))
8734 new_return(92);
8735
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litems, f))
8736 new_return(95);
8737
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if(!p_iputw(itemsbuf[i].pickup_litem_level, f))
8738 new_return(96);
8739
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if (!p_iputl(itemsbuf[i].moveflags, f))
8740 new_return(97);
8741
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(auto ret = write_weap_data(itemsbuf[i].weap_data, f))
8742 return ret;
8743
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
✗ Branch 3 not taken.
4608 if (!p_iputl(itemsbuf[i].cooldown, f))
8744 new_return(98);
8745
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4608 times.
4608 }
8746
8747
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8748 {
8749 9 section_size=writesize;
8750 9 }
8751 18 }
8752
8753
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8754 {
8755 char ebuf[80];
8756 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8757 jwin_alert("Error: writeitems()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8758 }
8759
8760 9 new_return(0);
8761 9 }
8762
8763 9 int32_t writeweapons(PACKFILE *f, zquestheader *Header)
8764 {
8765 //these are here to bypass compiler warnings about unused arguments
8766 9 Header=Header;
8767
8768 9 dword section_id=ID_WEAPONS;
8769 9 dword section_version=V_WEAPONS;
8770 9 dword section_size = 0;
8771
8772 //section id
8773
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
8774 {
8775 new_return(1);
8776 }
8777
8778 //section version info
8779
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
8780 {
8781 new_return(2);
8782 }
8783
8784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
8785 {
8786 new_return(3);
8787 }
8788
8789
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
8790 {
8791 18 fake_pack_writing=(writecycle==0);
8792
8793 //section size
8794
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
8795 {
8796 new_return(4);
8797 }
8798
8799 18 writesize=0;
8800
8801 //finally... section data
8802
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(MAXWPNS,f))
8803 {
8804 new_return(5);
8805 }
8806
8807
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8808 {
8809
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!pfwrite((char *)weapon_string[i], 64, f))
8810 {
8811 new_return(5);
8812 }
8813 4608 }
8814
8815
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(int32_t i=0; i<MAXWPNS; i++)
8816 {
8817
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].misc,f))
8818 {
8819 new_return(7);
8820 }
8821
8822
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].csets,f))
8823 {
8824 new_return(8);
8825 }
8826
8827
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].frames,f))
8828 {
8829 new_return(9);
8830 }
8831
8832
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].speed,f))
8833 {
8834 new_return(10);
8835 }
8836
8837
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_putc(wpnsbuf[i].type,f))
8838 {
8839 new_return(11);
8840 }
8841
8842
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputw(wpnsbuf[i].script,f))
8843 {
8844 new_return(12);
8845 }
8846
8847
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if(!p_iputl(wpnsbuf[i].tile,f))
8848 {
8849 new_return(12);
8850 }
8851 4608 }
8852
8853
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
8854 {
8855 9 section_size=writesize;
8856 9 }
8857 18 }
8858
8859
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
8860 {
8861 char ebuf[80];
8862 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
8863 jwin_alert("Error: writeweapons()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
8864 }
8865
8866 9 new_return(0);
8867 }
8868
8869 12784 int32_t writemapscreen(PACKFILE *f, int32_t i, int32_t j)
8870 {
8871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12784 times.
12784 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
8872 return qe_invalid;
8873
8874 12784 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
8875 12784 bool is_0x80_screen = j >= 0x80;
8876
8877
1/2
✓ Branch 0 taken 12784 times.
✗ Branch 1 not taken.
12784 if(!p_putc(screen.valid,f))
8878 return qe_invalid;
8879
2/2
✓ Branch 0 taken 8380 times.
✓ Branch 1 taken 4404 times.
12784 if(!(screen.valid & mVALID))
8880 4404 return qe_OK;
8881 //Calculate what needs writing
8882 8380 uint32_t scr_has_flags = 0;
8883
4/8
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8378 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
8380 if(screen.guytile || screen.guy || screen.roomflags || screen.str
8884
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 || screen.room || screen.catchall)
8885 8380 scr_has_flags |= SCRHAS_ROOMDATA;
8886
7/8
✓ Branch 0 taken 7946 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 192 times.
✓ Branch 3 taken 7754 times.
✓ Branch 4 taken 180 times.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 180 times.
8380 if(screen.hasitem || (is_0x80_screen && (screen.itemx||screen.itemy)))
8887 446 scr_has_flags |= SCRHAS_ITEM;
8888
3/4
✓ Branch 0 taken 8352 times.
✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8352 times.
8380 if((screen.warpreturnc&0x00FF) || screen.tilewarpoverlayflags)
8889 28 scr_has_flags |= SCRHAS_TWARP;
8890
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 32882 times.
41058 else for(auto q = 0; q < 4; ++q)
8891 {
8892
1/2
✓ Branch 0 taken 32706 times.
✗ Branch 1 not taken.
65588 if(screen.tilewarptype[q]
8893
2/2
✓ Branch 0 taken 32708 times.
✓ Branch 1 taken 174 times.
32882 || screen.tilewarpdmap[q]
8894
2/2
✓ Branch 0 taken 32706 times.
✓ Branch 1 taken 2 times.
32708 || screen.tilewarpscr[q])
8895 {
8896 176 scr_has_flags |= SCRHAS_TWARP;
8897 176 break;
8898 }
8899 32706 }
8900
3/4
✓ Branch 0 taken 8376 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8344 times.
8380 if((screen.warpreturnc&0xFF00) || screen.sidewarpindex
8901
2/2
✓ Branch 0 taken 8344 times.
✓ Branch 1 taken 32 times.
8376 || screen.sidewarpoverlayflags)
8902 36 scr_has_flags |= SCRHAS_SWARP;
8903
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 20568 times.
24642 else for(auto q = 0; q < 4; ++q)
8904 {
8905
2/2
✓ Branch 0 taken 16298 times.
✓ Branch 1 taken 12 times.
36878 if(screen.sidewarptype[q] != wtSCROLL
8906
2/2
✓ Branch 0 taken 16436 times.
✓ Branch 1 taken 4132 times.
20568 || screen.sidewarpdmap[q]
8907
2/2
✓ Branch 0 taken 16310 times.
✓ Branch 1 taken 126 times.
16436 || screen.sidewarpscr[q])
8908 {
8909 4270 scr_has_flags |= SCRHAS_SWARP;
8910 4270 break;
8911 }
8912 16298 }
8913
3/4
✓ Branch 0 taken 8336 times.
✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8336 times.
8380 if(screen.warparrivalx || screen.warparrivaly)
8914 44 scr_has_flags |= SCRHAS_WARPRET;
8915
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 30992 times.
38544 else for(auto q = 0; q < 4; ++q)
8916 {
8917
4/4
✓ Branch 0 taken 30210 times.
✓ Branch 1 taken 782 times.
✓ Branch 2 taken 30208 times.
✓ Branch 3 taken 2 times.
30992 if(screen.warpreturnx[q] || screen.warpreturny[q])
8918 {
8919 784 scr_has_flags |= SCRHAS_WARPRET;
8920 784 break;
8921 }
8922 30208 }
8923
8924
2/4
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8380 times.
8380 if(screen.hidelayers || screen.hidescriptlayers)
8925 scr_has_flags |= SCRHAS_LAYERS;
8926
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 45498 times.
52912 else for(auto q = 0; q < 6; ++q)
8927 {
8928
4/4
✓ Branch 0 taken 44552 times.
✓ Branch 1 taken 946 times.
✓ Branch 2 taken 44532 times.
✓ Branch 3 taken 20 times.
45498 if(screen.layermap[q] || screen.layerscreen[q]
8929
1/2
✓ Branch 0 taken 44552 times.
✗ Branch 1 not taken.
44552 || screen.layeropacity[q]!=255)
8930 {
8931 966 scr_has_flags |= SCRHAS_LAYERS;
8932 966 break;
8933 }
8934 44532 }
8935
8936
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 8370 times.
8380 if(screen.exitdir)
8937 10 scr_has_flags |= SCRHAS_MAZE;
8938
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8370 times.
8370 else if(screen.maze_transition_wipe)
8939 scr_has_flags |= SCRHAS_MAZE;
8940
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 33480 times.
41850 else for(auto q = 0; q < 4; ++q)
8941 {
8942
1/2
✓ Branch 0 taken 33480 times.
✗ Branch 1 not taken.
33480 if(screen.path[q])
8943 {
8944 scr_has_flags |= SCRHAS_MAZE;
8945 break;
8946 }
8947 33480 }
8948
8949
4/4
✓ Branch 0 taken 8146 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 322 times.
✓ Branch 3 taken 5412 times.
14114 if(screen.door_combo_set || screen.stairx
8950
3/4
✓ Branch 0 taken 8118 times.
✓ Branch 1 taken 28 times.
✓ Branch 2 taken 8118 times.
✗ Branch 3 not taken.
8146 || screen.stairy || screen.undercombo
8951
2/2
✓ Branch 0 taken 5734 times.
✓ Branch 1 taken 2384 times.
8118 || screen.undercset)
8952 2968 scr_has_flags |= SCRHAS_D_S_U;
8953
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 6012 times.
6212 else for(auto q = 0; q < 4; ++q)
8954 {
8955
2/2
✓ Branch 0 taken 800 times.
✓ Branch 1 taken 5212 times.
6012 if(screen.door[q] != dNONE)
8956 {
8957 5212 scr_has_flags |= SCRHAS_D_S_U;
8958 5212 break;
8959 }
8960 800 }
8961
8962
2/2
✓ Branch 0 taken 8076 times.
✓ Branch 1 taken 304 times.
15600 if(screen.flags || screen.flags2
8963
4/4
✓ Branch 0 taken 7830 times.
✓ Branch 1 taken 246 times.
✓ Branch 2 taken 7698 times.
✓ Branch 3 taken 132 times.
8076 || screen.flags3 || screen.flags4
8964
4/4
✓ Branch 0 taken 7684 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 7662 times.
✓ Branch 3 taken 22 times.
7698 || screen.flags5 || screen.flags6
8965
4/4
✓ Branch 0 taken 7448 times.
✓ Branch 1 taken 214 times.
✓ Branch 2 taken 7220 times.
✓ Branch 3 taken 228 times.
7662 || screen.flags7 || screen.flags8
8966
2/4
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 7220 times.
✗ Branch 3 not taken.
7220 || screen.flags9 || screen.flags10
8967
1/2
✓ Branch 0 taken 7220 times.
✗ Branch 1 not taken.
7220 || screen.flags11)
8968 8380 scr_has_flags |= SCRHAS_FLAGS;
8969
8970
2/2
✓ Branch 0 taken 58 times.
✓ Branch 1 taken 8322 times.
8380 if(screen.pattern)
8971 58 scr_has_flags |= SCRHAS_ENEMY;
8972
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 74100 times.
81408 else for(auto q = 0; q < 10; ++q)
8973 {
8974
2/2
✓ Branch 0 taken 73086 times.
✓ Branch 1 taken 1014 times.
74100 if(screen.enemy[q])
8975 {
8976 1014 scr_has_flags |= SCRHAS_ENEMY;
8977 1014 break;
8978 }
8979 73086 }
8980
8981
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8380 if(screen.noreset != mDEF_NORESET || screen.nocarry != mDEF_NOCARRYOVER
8982 || screen.nextmap || screen.nextscr || screen.exstate_reset || screen.exstate_carry)
8983 8380 scr_has_flags |= SCRHAS_CARRY;
8984
8985
3/4
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8358 times.
8380 if(screen.script || screen.preloadscript)
8986 22 scr_has_flags |= SCRHAS_SCRIPT;
8987
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 66864 times.
75222 else for(auto q = 0; q < 8; ++q)
8988 {
8989
1/2
✓ Branch 0 taken 66864 times.
✗ Branch 1 not taken.
66864 if(screen.screeninitd[q])
8990 {
8991 scr_has_flags |= SCRHAS_SCRIPT;
8992 break;
8993 }
8994 66864 }
8995
8996
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 683992 times.
689296 for(auto q = 0; q < 128; ++q)
8997 {
8998
1/2
✓ Branch 0 taken 680916 times.
✗ Branch 1 not taken.
1364908 if(screen.secretcombo[q]
8999
2/2
✓ Branch 0 taken 680922 times.
✓ Branch 1 taken 3070 times.
683992 || screen.secretcset[q]
9000
2/2
✓ Branch 0 taken 680916 times.
✓ Branch 1 taken 6 times.
680922 || screen.secretflag[q])
9001 {
9002 3076 scr_has_flags |= SCRHAS_SECRETS;
9003 3076 break;
9004 }
9005 680916 }
9006
9007
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 573892 times.
576912 for(auto q = 0; q < 176; ++q)
9008 {
9009
4/4
✓ Branch 0 taken 568780 times.
✓ Branch 1 taken 5112 times.
✓ Branch 2 taken 568532 times.
✓ Branch 3 taken 12 times.
573892 if(screen.data[q] || screen.cset[q]
9010
2/2
✓ Branch 0 taken 568544 times.
✓ Branch 1 taken 236 times.
568780 || screen.sflag[q])
9011 {
9012 5360 scr_has_flags |= SCRHAS_COMBOFLAG;
9013 5360 break;
9014 }
9015 568532 }
9016
9017
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 2236 times.
8380 if(screen.color || screen.csensitive != 1
9018
3/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6110 times.
✓ Branch 3 taken 34 times.
6144 || screen.oceansfx || screen.bosssfx
9019
2/4
✓ Branch 0 taken 6110 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6110 times.
6110 || screen.secretsfx || screen.holdupsfx
9020 || screen.timedwarptics || screen.screen_midi != -1
9021 || screen.lens_layer || screen.lens_show || screen.lens_hide)
9022 8380 scr_has_flags |= SCRHAS_MISC;
9023
9024
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(scr_has_flags,f))
9025 return qe_invalid;
9026
9027 //Write stuff
9028
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_ROOMDATA)
9029 {
9030
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guy,f))
9031 return qe_invalid;
9032
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.guytile,f))
9033 return qe_invalid;
9034
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.guycs,f))
9035 return qe_invalid;
9036
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.roomflags,f))
9037 return qe_invalid;
9038
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.str,f))
9039 return qe_invalid;
9040
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.room,f))
9041 return qe_invalid;
9042
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.catchall,f))
9043 return qe_invalid;
9044 8380 }
9045
2/2
✓ Branch 0 taken 7934 times.
✓ Branch 1 taken 446 times.
8380 if(scr_has_flags & SCRHAS_ITEM)
9046 {
9047
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.item,f))
9048 return qe_invalid;
9049
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.hasitem,f))
9050 return qe_invalid;
9051
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemx,f))
9052 return qe_invalid;
9053
1/2
✓ Branch 0 taken 446 times.
✗ Branch 1 not taken.
446 if(!p_putc(screen.itemy,f))
9054 return qe_invalid;
9055 446 }
9056
2/2
✓ Branch 0 taken 4006 times.
✓ Branch 1 taken 4374 times.
8380 if(scr_has_flags & (SCRHAS_SWARP|SCRHAS_TWARP))
9057 {
9058
1/2
✓ Branch 0 taken 4374 times.
✗ Branch 1 not taken.
4374 if(!p_iputw(screen.warpreturnc,f))
9059 return qe_invalid;
9060 4374 }
9061
2/2
✓ Branch 0 taken 8176 times.
✓ Branch 1 taken 204 times.
8380 if(scr_has_flags & SCRHAS_TWARP)
9062 {
9063
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9064 {
9065
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarptype[k],f))
9066 return qe_invalid;
9067 816 }
9068
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9069 {
9070
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_iputw(screen.tilewarpdmap[k],f))
9071 return qe_invalid;
9072 816 }
9073
9074
2/2
✓ Branch 0 taken 816 times.
✓ Branch 1 taken 204 times.
1020 for(int32_t k=0; k<4; k++)
9075 {
9076
1/2
✓ Branch 0 taken 816 times.
✗ Branch 1 not taken.
816 if(!p_putc(screen.tilewarpscr[k],f))
9077 return qe_invalid;
9078 816 }
9079
9080
1/2
✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
204 if(!p_putc(screen.tilewarpoverlayflags,f))
9081 return qe_invalid;
9082 204 }
9083
2/2
✓ Branch 0 taken 4074 times.
✓ Branch 1 taken 4306 times.
8380 if(scr_has_flags & SCRHAS_SWARP)
9084 {
9085
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9086 {
9087
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarptype[k],f))
9088 return qe_invalid;
9089 17224 }
9090
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9091 {
9092
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_iputw(screen.sidewarpdmap[k],f))
9093 return qe_invalid;
9094 17224 }
9095
9096
2/2
✓ Branch 0 taken 17224 times.
✓ Branch 1 taken 4306 times.
21530 for(int32_t k=0; k<4; k++)
9097 {
9098
1/2
✓ Branch 0 taken 17224 times.
✗ Branch 1 not taken.
17224 if(!p_putc(screen.sidewarpscr[k],f))
9099 return qe_invalid;
9100 17224 }
9101
9102
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpoverlayflags,f))
9103 return qe_invalid;
9104
1/2
✓ Branch 0 taken 4306 times.
✗ Branch 1 not taken.
4306 if(!p_putc(screen.sidewarpindex,f))
9105 return qe_invalid;
9106 4306 }
9107
2/2
✓ Branch 0 taken 7552 times.
✓ Branch 1 taken 828 times.
8380 if(scr_has_flags & SCRHAS_WARPRET)
9108 {
9109
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9110 {
9111
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturnx[k],f))
9112 return qe_invalid;
9113 3312 }
9114
2/2
✓ Branch 0 taken 3312 times.
✓ Branch 1 taken 828 times.
4140 for(int32_t k=0; k<4; k++)
9115 {
9116
1/2
✓ Branch 0 taken 3312 times.
✗ Branch 1 not taken.
3312 if(!p_putc(screen.warpreturny[k],f))
9117 return qe_invalid;
9118 3312 }
9119
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivalx,f))
9120 return qe_invalid;
9121
1/2
✓ Branch 0 taken 828 times.
✗ Branch 1 not taken.
828 if(!p_putc(screen.warparrivaly,f))
9122 return qe_invalid;
9123 828 }
9124
2/2
✓ Branch 0 taken 7414 times.
✓ Branch 1 taken 966 times.
8380 if(scr_has_flags & SCRHAS_LAYERS)
9125 {
9126
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9127 {
9128
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layermap[k],f))
9129 return qe_invalid;
9130 5796 }
9131
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9132 {
9133
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layerscreen[k],f))
9134 return qe_invalid;
9135 5796 }
9136
2/2
✓ Branch 0 taken 5796 times.
✓ Branch 1 taken 966 times.
6762 for(int32_t k=0; k<6; k++)
9137 {
9138
1/2
✓ Branch 0 taken 5796 times.
✗ Branch 1 not taken.
5796 if(!p_putc(screen.layeropacity[k],f))
9139 return qe_invalid;
9140 5796 }
9141
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidelayers,f))
9142 return qe_invalid;
9143
1/2
✓ Branch 0 taken 966 times.
✗ Branch 1 not taken.
966 if(!p_putc(screen.hidescriptlayers,f))
9144 return qe_invalid;
9145 966 }
9146
2/2
✓ Branch 0 taken 8370 times.
✓ Branch 1 taken 10 times.
8380 if(scr_has_flags & SCRHAS_MAZE)
9147 {
9148
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 10 times.
50 for(int32_t k=0; k<4; k++)
9149 {
9150
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if(!p_putc(screen.path[k],f))
9151 return qe_invalid;
9152 40 }
9153
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.exitdir,f))
9154 return qe_invalid;
9155
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_putc(screen.maze_transition_wipe,f))
9156 return qe_invalid;
9157 10 }
9158
2/2
✓ Branch 0 taken 200 times.
✓ Branch 1 taken 8180 times.
8380 if(scr_has_flags & SCRHAS_D_S_U)
9159 {
9160
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.door_combo_set,f))
9161 return qe_invalid;
9162
2/2
✓ Branch 0 taken 32720 times.
✓ Branch 1 taken 8180 times.
40900 for(int32_t k=0; k<4; k++)
9163 {
9164
1/2
✓ Branch 0 taken 32720 times.
✗ Branch 1 not taken.
32720 if(!p_putc(screen.door[k],f))
9165 return qe_invalid;
9166 32720 }
9167
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairx,f))
9168 return qe_invalid;
9169
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.stairy,f))
9170 return qe_invalid;
9171
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_iputw(screen.undercombo,f))
9172 return qe_invalid;
9173
1/2
✓ Branch 0 taken 8180 times.
✗ Branch 1 not taken.
8180 if(!p_putc(screen.undercset,f))
9174 return qe_invalid;
9175 8180 }
9176
2/2
✓ Branch 0 taken 7086 times.
✓ Branch 1 taken 1294 times.
8380 if(scr_has_flags & SCRHAS_FLAGS)
9177 {
9178
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags,f))
9179 return qe_invalid;
9180
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags2,f))
9181 return qe_invalid;
9182
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags3,f))
9183 return qe_invalid;
9184
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags4,f))
9185 return qe_invalid;
9186
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags5,f))
9187 return qe_invalid;
9188
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags6,f))
9189 return qe_invalid;
9190
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags7,f))
9191 return qe_invalid;
9192
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags8,f))
9193 return qe_invalid;
9194
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags9,f))
9195 return qe_invalid;
9196
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags10,f))
9197 return qe_invalid;
9198
1/2
✓ Branch 0 taken 1294 times.
✗ Branch 1 not taken.
1294 if(!p_putc(screen.flags11,f))
9199 return qe_invalid;
9200 1294 }
9201
2/2
✓ Branch 0 taken 7308 times.
✓ Branch 1 taken 1072 times.
8380 if(scr_has_flags & SCRHAS_ENEMY)
9202 {
9203
2/2
✓ Branch 0 taken 10720 times.
✓ Branch 1 taken 1072 times.
11792 for(int32_t k=0; k<10; k++)
9204 {
9205
1/2
✓ Branch 0 taken 10720 times.
✗ Branch 1 not taken.
10720 if(!p_iputw(screen.enemy[k],f))
9206 return qe_invalid;
9207 10720 }
9208
1/2
✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
1072 if(!p_putc(screen.pattern,f))
9209 return qe_invalid;
9210 1072 }
9211
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_CARRY)
9212 {
9213
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.noreset,f))
9214 return qe_invalid;
9215
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.nocarry,f))
9216 return qe_invalid;
9217
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_reset,f))
9218 return qe_invalid;
9219
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputl(screen.exstate_carry,f))
9220 return qe_invalid;
9221
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextmap,f))
9222 return qe_invalid;
9223
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.nextscr,f))
9224 return qe_invalid;
9225 8380 }
9226
2/2
✓ Branch 0 taken 8358 times.
✓ Branch 1 taken 22 times.
8380 if(scr_has_flags & SCRHAS_SCRIPT)
9227 {
9228
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(screen.script,f))
9229 return qe_invalid;
9230
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_putc(screen.preloadscript,f))
9231 return qe_invalid;
9232
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 22 times.
198 for ( int32_t q = 0; q < 8; q++ )
9233 {
9234
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if(!p_iputl(screen.screeninitd[q],f))
9235 return qe_invalid;
9236 176 }
9237 22 }
9238
2/2
✓ Branch 0 taken 5304 times.
✓ Branch 1 taken 3076 times.
8380 if(scr_has_flags & SCRHAS_SECRETS)
9239 {
9240
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9241 {
9242
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_iputw(screen.secretcombo[k],f))
9243 return qe_invalid;
9244 393728 }
9245
9246
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9247 {
9248
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretcset[k],f))
9249 return qe_invalid;
9250 393728 }
9251
9252
2/2
✓ Branch 0 taken 393728 times.
✓ Branch 1 taken 3076 times.
396804 for(int32_t k=0; k<128; k++)
9253 {
9254
1/2
✓ Branch 0 taken 393728 times.
✗ Branch 1 not taken.
393728 if(!p_putc(screen.secretflag[k],f))
9255 return qe_invalid;
9256 393728 }
9257 3076 }
9258
2/2
✓ Branch 0 taken 3020 times.
✓ Branch 1 taken 5360 times.
8380 if(scr_has_flags & SCRHAS_COMBOFLAG)
9259 {
9260
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9261 {
9262
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_iputw(screen.data[k],f))
9263 return qe_invalid;
9264 943360 }
9265
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9266 {
9267
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.sflag[k],f))
9268 return qe_invalid;
9269 943360 }
9270
2/2
✓ Branch 0 taken 943360 times.
✓ Branch 1 taken 5360 times.
948720 for(int32_t k=0; k<176; ++k)
9271 {
9272
1/2
✓ Branch 0 taken 943360 times.
✗ Branch 1 not taken.
943360 if(!p_putc(screen.cset[k],f))
9273 return qe_invalid;
9274 943360 }
9275 5360 }
9276
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(scr_has_flags & SCRHAS_MISC)
9277 {
9278
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.color,f))
9279 return qe_invalid;
9280
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.csensitive,f))
9281 return qe_invalid;
9282
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.oceansfx,f))
9283 return qe_invalid;
9284
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.bosssfx,f))
9285 return qe_invalid;
9286
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.secretsfx,f))
9287 return qe_invalid;
9288
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.holdupsfx,f))
9289 return qe_invalid;
9290
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.timedwarptics,f))
9291 return qe_invalid;
9292
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(screen.screen_midi,f))
9293 return qe_invalid;
9294
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_layer,f))
9295 return qe_invalid;
9296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8380 times.
8380 if(!p_putc(screen.lens_show,f))
9297 return qe_invalid;
9298
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putc(screen.lens_hide,f))
9299 return qe_invalid;
9300 8380 }
9301
9302 8380 dword numffc = screen.numFFC();
9303
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_iputw(numffc,f))
9304 return qe_invalid;
9305
2/2
✓ Branch 0 taken 245678 times.
✓ Branch 1 taken 8380 times.
254058 for(int32_t k=0; k<numffc; ++k)
9306 {
9307 245678 ffcdata const& tempffc = screen.ffcs[k];
9308
9309
1/2
✓ Branch 0 taken 245678 times.
✗ Branch 1 not taken.
245678 if(!p_iputw(tempffc.data,f))
9310 return qe_invalid;
9311
9312
2/2
✓ Branch 0 taken 2314 times.
✓ Branch 1 taken 243364 times.
245678 if(!tempffc.data) //don't save the rest of the ffc
9313 243364 continue;
9314
9315
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.cset,f))
9316 return qe_invalid;
9317
9318
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.delay,f))
9319 return qe_invalid;
9320
9321
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.x,f))
9322 return qe_invalid;
9323
9324
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.y,f))
9325 return qe_invalid;
9326
9327
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vx,f))
9328 return qe_invalid;
9329
9330
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.vy,f))
9331 return qe_invalid;
9332
9333
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ax,f))
9334 return qe_invalid;
9335
9336
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputzf(tempffc.ay,f))
9337 return qe_invalid;
9338
9339
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.link,f))
9340 return qe_invalid;
9341
9342
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_width,f))
9343 return qe_invalid;
9344
9345
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.hit_height,f))
9346 return qe_invalid;
9347
9348
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.txsz,f))
9349 return qe_invalid;
9350
9351
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.tysz,f))
9352 return qe_invalid;
9353
9354
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputl(tempffc.flags,f))
9355 return qe_invalid;
9356
9357
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_iputw(tempffc.script,f))
9358 return qe_invalid;
9359
9360
2/2
✓ Branch 0 taken 18512 times.
✓ Branch 1 taken 2314 times.
20826 for(auto q = 0; q < 8; ++q)
9361 {
9362
1/2
✓ Branch 0 taken 18512 times.
✗ Branch 1 not taken.
18512 if(!p_iputl(tempffc.initd[q],f))
9363 return qe_invalid;
9364 18512 }
9365
9366
1/2
✓ Branch 0 taken 2314 times.
✗ Branch 1 not taken.
2314 if(!p_putc(tempffc.layer,f))
9367 return qe_invalid;
9368 2314 }
9369
9370
1/2
✓ Branch 0 taken 8380 times.
✗ Branch 1 not taken.
8380 if(!p_putlstr(screen.usr_notes, f))
9371 return qe_invalid;
9372
9373
2/2
✓ Branch 0 taken 8374 times.
✓ Branch 1 taken 6 times.
8380 if (screen.flags10 & fSCREEN_GRAVITY)
9374 {
9375
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_gravity, f))
9376 return qe_invalid;
9377
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!p_iputzf(screen.screen_terminal_v, f))
9378 return qe_invalid;
9379 6 }
9380
9381 8380 return qe_OK;
9382 12784 }
9383
9384 9 int32_t writemaps(PACKFILE *f, zquestheader *)
9385 {
9386 9 dword section_id=ID_MAPS;
9387 9 dword section_version=V_MAPS;
9388 9 dword section_size = 0;
9389
9390 //section id
9391
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9392 {
9393 new_return(1);
9394 }
9395
9396 //section version info
9397
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9398 {
9399 new_return(2);
9400 }
9401
9402
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9403 {
9404 new_return(3);
9405 }
9406
9407
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9408 {
9409 18 fake_pack_writing=(writecycle==0);
9410
9411 //section size
9412
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9413 {
9414 new_return(4);
9415 }
9416
9417 18 writesize=0;
9418
9419
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(map_count,f))
9420 {
9421 new_return(5);
9422 }
9423 18 map_infos.resize(map_count);
9424
4/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 18 times.
118 for(int32_t i=0; i<map_count && i<MAXMAPS; i++)
9425 {
9426 100 byte valid = 0;
9427
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1282 times.
1288 for(int32_t j=0; j<MAPSCRS; j++)
9428 {
9429
1/2
✓ Branch 0 taken 1282 times.
✗ Branch 1 not taken.
1282 if((i*MAPSCRS+j)>=int32_t(TheMaps.size()))
9430 break;
9431 1282 mapscr& screen=TheMaps.at(i*MAPSCRS+j);
9432
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 1188 times.
1282 if (screen.is_valid())
9433 {
9434 94 valid = 1;
9435 94 break;
9436 }
9437 1188 }
9438
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if(!p_putc(valid,f))
9439 {
9440 new_return(6);
9441 }
9442
2/2
✓ Branch 0 taken 94 times.
✓ Branch 1 taken 6 times.
100 if(!valid) continue;
9443
9444 { //per-map info
9445 94 auto const& mapinf = map_infos[i];
9446
2/2
✓ Branch 0 taken 564 times.
✓ Branch 1 taken 94 times.
658 for(int q = 0; q < 6; ++q)
9447 {
9448
1/2
✓ Branch 0 taken 564 times.
✗ Branch 1 not taken.
564 if(!p_iputw(mapinf.autolayers[q],f))
9449 new_return(7);
9450 564 }
9451
1/2
✓ Branch 0 taken 94 times.
✗ Branch 1 not taken.
94 if(!p_iputw(mapinf.autopalette,f))
9452 new_return(9);
9453
9454
9455
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 94 times.
846 for(int32_t j=0; j<8; j++)
9456 {
9457
2/2
✓ Branch 0 taken 752 times.
✓ Branch 1 taken 6016 times.
6768 for(int32_t k=0; k<8; k++)
9458 {
9459
1/2
✓ Branch 0 taken 6016 times.
✗ Branch 1 not taken.
6016 if(!p_putc(Regions[i].region_ids[j][k],f))
9460 {
9461 new_return(8);
9462 }
9463 6016 }
9464 752 }
9465 }
9466
9467
2/2
✓ Branch 0 taken 12784 times.
✓ Branch 1 taken 94 times.
12878 for(int32_t j=0; j<MAPSCRS; j++)
9468 12784 writemapscreen(f,i,j);
9469 94 }
9470
9471
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9472 {
9473 9 section_size=writesize;
9474 9 }
9475 18 }
9476
9477
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9478 {
9479 char ebuf[80];
9480 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9481 jwin_alert("Error: writemaps()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9482 }
9483
9484 9 new_return(0);
9485 }
9486
9487 460 int32_t writecombo_triggers_loop(PACKFILE *f, word section_version, combo_trigger const& tmp_trig)
9488 {
9489
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putcstr(tmp_trig.label,f))
9490 return 22;
9491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.trigger_flags,f))
9492 return 22;
9493
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.triggerlevel,f))
9494 return 23;
9495
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggerbtn,f))
9496 return 34;
9497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triggeritem,f))
9498 return 35;
9499
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigtimer,f))
9500 return 36;
9501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigsfx,f))
9502 return 37;
9503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigchange,f))
9504 return 38;
9505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigprox,f))
9506 return 39;
9507
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigctr,f))
9508 return 40;
9509
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trigctramnt,f))
9510 return 41;
9511
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.triglbeam,f))
9512 return 42;
9513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcschange,f))
9514 return 43;
9515
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnitem,f))
9516 return 44;
9517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.spawnenemy,f))
9518 return 45;
9519
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exstate,f))
9520 return 46;
9521
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.spawnip,f))
9522 return 47;
9523
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcopycat,f))
9524 return 48;
9525
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trigcooldown,f))
9526 return 49;
9527
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_cid,f))
9528 return 50;
9529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.prompt_cs,f))
9530 return 51;
9531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_x,f))
9532 return 52;
9533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.prompt_y,f))
9534 return 53;
9535
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_lstate,f))
9536 return 69;
9537
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_gstate,f))
9538 return 70;
9539
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputl(tmp_trig.trig_statetime,f))
9540 return 71;
9541
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_genscr,f))
9542 return 72;
9543
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.trig_group,f))
9544 return 76;
9545
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_group_val,f))
9546 return 77;
9547
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_dir,f))
9548 return 89;
9549
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putc(tmp_trig.exdoor_ind,f))
9550 return 90;
9551
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_levelitems,f))
9552 return 91;
9553
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trigdmlevel,f))
9554 return 92;
9555
2/2
✓ Branch 0 taken 1380 times.
✓ Branch 1 taken 460 times.
1840 for(int q = 0; q < 3; ++q)
9556
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1380 times.
1380 if(!p_iputw(tmp_trig.trigtint[q],f))
9557 return 93;
9558
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.triglvlpalette,f))
9559 return 94;
9560
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigbosspalette,f))
9561 return 95;
9562
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigquaketime,f))
9563 return 96;
9564
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trigwavytime,f))
9565 return 97;
9566
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_swjinxtime,f))
9567 return 98;
9568
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_itmjinxtime,f))
9569 return 99;
9570
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputw(tmp_trig.trig_stuntime,f))
9571 return 100;
9572
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.trig_bunnytime,f))
9573 return 101;
9574
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.trig_pushtime,f))
9575 return 102;
9576
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputw(tmp_trig.trig_shieldjinxtime, f))
9577 return 103;
9578
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.req_level_state, f))
9579 return 104;
9580
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.unreq_level_state, f))
9581 return 105;
9582
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_putbitstr(tmp_trig.req_global_state, f))
9583 return 106;
9584
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putbitstr(tmp_trig.unreq_global_state, f))
9585 return 107;
9586
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputw(tmp_trig.fail_prompt_cid, f))
9587 return 108;
9588
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.fail_prompt_cs, f))
9589 return 109;
9590
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.trig_msgstr, f))
9591 return 110;
9592
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.fail_msgstr, f))
9593 return 111;
9594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.player_bounce, f))
9595 return 112;
9596
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_z, f))
9597 return 113;
9598
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.req_player_dir, f))
9599 return 114;
9600
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_x, f))
9601 return 115;
9602
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_y, f))
9603 return 116;
9604
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.dest_player_z, f))
9605 return 117;
9606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.req_player_jump, f))
9607 return 118;
9608
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_x, f))
9609 return 119;
9610
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.req_player_y, f))
9611 return 120;
9612
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_trig.dest_player_dir, f))
9613 return 121;
9614
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputl(tmp_trig.force_ice_combo, f))
9615 return 122;
9616
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.force_ice_vx, f))
9617 return 123;
9618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 460 times.
460 if(!p_iputzf(tmp_trig.force_ice_vy, f))
9619 return 124;
9620
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_gravity, f))
9621 return 125;
9622
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_iputzf(tmp_trig.trig_terminal_v, f))
9623 return 126;
9624 460 return 0;
9625 460 }
9626 258906 int32_t writecombo_loop(PACKFILE *f, word section_version, newcombo const& tmp_cmb)
9627 {
9628 //Check what needs writing
9629 258906 word combo_has_flags = 0;
9630
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 2056150 times.
2311866 for(auto q = 0; q < 8; ++q)
9631 {
9632
4/4
✓ Branch 0 taken 2054470 times.
✓ Branch 1 taken 1680 times.
✓ Branch 2 taken 1028294 times.
✓ Branch 3 taken 1382 times.
3085826 if(tmp_cmb.attribytes[q] || tmp_cmb.attrishorts[q]
9633
4/4
✓ Branch 0 taken 2054342 times.
✓ Branch 1 taken 128 times.
✓ Branch 2 taken 1029676 times.
✓ Branch 3 taken 1024666 times.
2054470 || (q < 4 && tmp_cmb.attributes[q]))
9634 {
9635 3190 combo_has_flags |= CHAS_ATTRIB;
9636 3190 break;
9637 }
9638 2052960 }
9639
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if (!tmp_cmb.triggers.empty())
9640 460 combo_has_flags |= CHAS_TRIG;
9641
4/4
✓ Branch 0 taken 258628 times.
✓ Branch 1 taken 278 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 258608 times.
258906 if(tmp_cmb.usrflags || tmp_cmb.genflags)
9642 298 combo_has_flags |= CHAS_FLAG;
9643
6/6
✓ Branch 0 taken 251806 times.
✓ Branch 1 taken 7100 times.
✓ Branch 2 taken 231382 times.
✓ Branch 3 taken 20424 times.
✓ Branch 4 taken 532 times.
✓ Branch 5 taken 230732 times.
490170 if(tmp_cmb.frames || tmp_cmb.speed || tmp_cmb.nextcombo
9644
6/6
✓ Branch 0 taken 231358 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 231320 times.
✓ Branch 3 taken 38 times.
✓ Branch 4 taken 231264 times.
✓ Branch 5 taken 56 times.
231382 || tmp_cmb.nextcset || tmp_cmb.skipanim || tmp_cmb.skipanimy
9645
1/2
✓ Branch 0 taken 231264 times.
✗ Branch 1 not taken.
231264 || tmp_cmb.animflags)
9646 28174 combo_has_flags |= CHAS_ANIM;
9647
3/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 258900 times.
258906 if(tmp_cmb.script || tmp_cmb.label.size())
9648 6 combo_has_flags |= CHAS_SCRIPT;
9649
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 2071200 times.
2330100 else for(auto q = 0; q < 8; ++q)
9650 {
9651
1/2
✓ Branch 0 taken 2071200 times.
✗ Branch 1 not taken.
2071200 if(tmp_cmb.initd[q])
9652 {
9653 combo_has_flags |= CHAS_SCRIPT;
9654 break;
9655 }
9656 2071200 }
9657
5/6
✓ Branch 0 taken 176904 times.
✓ Branch 1 taken 82002 times.
✓ Branch 2 taken 176392 times.
✓ Branch 3 taken 512 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 176392 times.
435298 if(tmp_cmb.o_tile || tmp_cmb.flip || tmp_cmb.walk != 0xF0
9658
2/4
✓ Branch 0 taken 176392 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 176392 times.
✗ Branch 3 not taken.
176392 || tmp_cmb.type || tmp_cmb.csets)
9659 82514 combo_has_flags |= CHAS_BASIC;
9660
3/4
✓ Branch 0 taken 258898 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
517802 if(tmp_cmb.liftcmb || tmp_cmb.liftcs || tmp_cmb.liftdmg
9661
3/6
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftlvl || tmp_cmb.liftitm || tmp_cmb.liftflags
9662
4/6
✓ Branch 0 taken 258896 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258896 times.
✗ Branch 5 not taken.
258898 || tmp_cmb.liftgfx || tmp_cmb.liftsprite || tmp_cmb.liftsfx
9663
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftundercmb || tmp_cmb.liftundercs
9664
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.liftbreaksprite!=-1 || tmp_cmb.liftbreaksfx
9665
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lifthei!=8 || tmp_cmb.lifttime!=16
9666
2/4
✓ Branch 0 taken 258896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258896 times.
✗ Branch 3 not taken.
258896 || tmp_cmb.lift_parent_item || !tmp_cmb.lift_weap_data.is_blank())
9667 10 combo_has_flags |= CHAS_LIFT;
9668
2/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258906 times.
✗ Branch 3 not taken.
515612 if(tmp_cmb.speed_mult != 1 || tmp_cmb.speed_div != 1 || tmp_cmb.speed_add
9669
7/10
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258902 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 258898 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258906 || tmp_cmb.sfx_appear || tmp_cmb.sfx_disappear || tmp_cmb.sfx_loop || tmp_cmb.sfx_walking || tmp_cmb.sfx_standing
9670
5/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 258898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 258898 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 258898 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 258898 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.spr_appear || tmp_cmb.spr_disappear || tmp_cmb.spr_walking || tmp_cmb.spr_standing || tmp_cmb.sfx_tap
9671
6/10
✓ Branch 0 taken 258898 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✓ Branch 3 taken 2192 times.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256706 times.
✗ Branch 9 not taken.
258898 || tmp_cmb.sfx_landing || tmp_cmb.spr_falling || tmp_cmb.spr_drowning || tmp_cmb.spr_lava_drowning || tmp_cmb.sfx_falling
9672
4/8
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 256706 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 256706 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 256706 times.
✗ Branch 7 not taken.
256706 || tmp_cmb.sfx_drowning || tmp_cmb.sfx_lava_drowning || tmp_cmb.z_height || tmp_cmb.z_step_height
9673
1/2
✓ Branch 0 taken 256706 times.
✗ Branch 1 not taken.
256706 || tmp_cmb.dive_under_level)
9674 258906 combo_has_flags |= CHAS_GENERAL;
9675
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!tmp_cmb.misc_weap_data.is_blank())
9676 combo_has_flags |= CHAS_MISC_WEAP_DATA;
9677
9678
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(combo_has_flags,f))
9679 {
9680 return 50;
9681 }
9682
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!combo_has_flags) return 0; //Valid, done writing
9683 //Write the combo
9684
2/2
✓ Branch 0 taken 176392 times.
✓ Branch 1 taken 82514 times.
258906 if(combo_has_flags&CHAS_BASIC)
9685 {
9686
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_iputl(tmp_cmb.o_tile,f))
9687 return 6;
9688
9689
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flip,f))
9690 return 7;
9691
9692
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.walk,f))
9693 return 8;
9694
9695
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.type,f))
9696 return 9;
9697
9698
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.flag,f))
9699 return 15;
9700
9701
1/2
✓ Branch 0 taken 82514 times.
✗ Branch 1 not taken.
82514 if(!p_putc(tmp_cmb.csets,f))
9702 return 10;
9703 82514 }
9704
2/2
✓ Branch 0 taken 258900 times.
✓ Branch 1 taken 6 times.
258906 if(combo_has_flags&CHAS_SCRIPT)
9705 {
9706 6 p_putcstr(tmp_cmb.label, f);
9707
9708
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(tmp_cmb.script,f))
9709 return 26;
9710
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for ( int32_t q = 0; q < 8; q++ )
9711
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(!p_iputl(tmp_cmb.initd[q],f))
9712 return 27;
9713 6 }
9714
2/2
✓ Branch 0 taken 230732 times.
✓ Branch 1 taken 28174 times.
258906 if(combo_has_flags&CHAS_ANIM)
9715 {
9716
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.frames,f))
9717 return 11;
9718
9719
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.speed,f))
9720 return 12;
9721
9722
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_iputw(tmp_cmb.nextcombo,f))
9723 return 13;
9724
9725
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.nextcset,f))
9726 return 14;
9727
9728
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanim,f))
9729 return 16;
9730
9731
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.skipanimy,f))
9732 return 18;
9733
9734
1/2
✓ Branch 0 taken 28174 times.
✗ Branch 1 not taken.
28174 if(!p_putc(tmp_cmb.animflags,f))
9735 return 19;
9736 28174 }
9737
2/2
✓ Branch 0 taken 255716 times.
✓ Branch 1 taken 3190 times.
258906 if(combo_has_flags&CHAS_ATTRIB)
9738 {
9739
2/2
✓ Branch 0 taken 12760 times.
✓ Branch 1 taken 3190 times.
15950 for ( int32_t q = 0; q < 4; q++ )
9740
1/2
✓ Branch 0 taken 12760 times.
✗ Branch 1 not taken.
12760 if(!p_iputl(tmp_cmb.attributes[q],f))
9741 return 20;
9742
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ )
9743
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_putc(tmp_cmb.attribytes[q],f))
9744 return 25;
9745
2/2
✓ Branch 0 taken 25520 times.
✓ Branch 1 taken 3190 times.
28710 for ( int32_t q = 0; q < 8; q++ ) //I also added attrishorts -Dimi
9746
1/2
✓ Branch 0 taken 25520 times.
✗ Branch 1 not taken.
25520 if(!p_iputw(tmp_cmb.attrishorts[q],f))
9747 return 32;
9748 3190 }
9749
2/2
✓ Branch 0 taken 258608 times.
✓ Branch 1 taken 298 times.
258906 if(combo_has_flags&CHAS_FLAG)
9750 {
9751
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputl(tmp_cmb.usrflags,f))
9752 return 21;
9753
1/2
✓ Branch 0 taken 298 times.
✗ Branch 1 not taken.
298 if(!p_iputw(tmp_cmb.genflags,f))
9754 return 33;
9755 298 }
9756
2/2
✓ Branch 0 taken 258446 times.
✓ Branch 1 taken 460 times.
258906 if(combo_has_flags&CHAS_TRIG)
9757 {
9758
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 byte sz = zc_min(tmp_cmb.triggers.size(), 255);
9759
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(sz,f))
9760 return 34;
9761
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 460 times.
920 for(byte q = 0; q < sz; ++q)
9762 {
9763 460 auto ret = writecombo_triggers_loop(f, section_version, tmp_cmb.triggers[q]);
9764
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(ret) return ret;
9765 460 }
9766
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if(!p_putc(tmp_cmb.only_gentrig,f))
9767 return 35;
9768 460 }
9769
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(combo_has_flags&CHAS_LIFT)
9770 {
9771
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftcmb,f))
9772 return 54;
9773
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftcs,f))
9774 return 55;
9775
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftundercmb,f))
9776 return 56;
9777
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftundercs,f))
9778 return 57;
9779
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftdmg,f))
9780 return 58;
9781
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftlvl,f))
9782 return 59;
9783
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftitm,f))
9784 return 60;
9785
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftflags,f))
9786 return 61;
9787
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftgfx,f))
9788 return 62;
9789
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsprite,f))
9790 return 63;
9791
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftsfx,f))
9792 return 64;
9793
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_iputw(tmp_cmb.liftbreaksprite,f))
9794 return 65;
9795
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.liftbreaksfx,f))
9796 return 66;
9797
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifthei,f))
9798 return 67;
9799
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lifttime,f))
9800 return 68;
9801
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(!p_putc(tmp_cmb.lift_parent_item,f))
9802 return 78;
9803
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 258906 times.
258906 if(auto ret = write_weap_data(tmp_cmb.lift_weap_data, f))
9804 return ret;
9805 258906 }
9806
2/2
✓ Branch 0 taken 256706 times.
✓ Branch 1 taken 2200 times.
258906 if(combo_has_flags&CHAS_GENERAL)
9807 {
9808
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_mult,f))
9809 return 73;
9810
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.speed_div,f))
9811 return 74;
9812
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.speed_add,f))
9813 return 75;
9814
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_appear,f))
9815 return 79;
9816
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_disappear,f))
9817 return 80;
9818
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_loop,f))
9819 return 81;
9820
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_walking,f))
9821 return 82;
9822
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_standing,f))
9823 return 83;
9824
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_appear,f))
9825 return 84;
9826
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_disappear,f))
9827 return 85;
9828
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_walking,f))
9829 return 86;
9830
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_standing,f))
9831 return 87;
9832
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_tap,f))
9833 return 88;
9834
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_landing,f))
9835 return 89;
9836
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_falling,f))
9837 return 90;
9838
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_drowning,f))
9839 return 91;
9840
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.spr_lava_drowning,f))
9841 return 92;
9842
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_falling,f))
9843 return 93;
9844
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_drowning,f))
9845 return 94;
9846
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_putc(tmp_cmb.sfx_lava_drowning,f))
9847 return 95;
9848
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_height,f))
9849 return 96;
9850
1/2
✓ Branch 0 taken 2200 times.
✗ Branch 1 not taken.
2200 if(!p_iputzf(tmp_cmb.z_step_height,f))
9851 return 97;
9852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2200 times.
2200 if(!p_putc(tmp_cmb.dive_under_level,f))
9853 return 98;
9854 2200 }
9855
1/2
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
258906 if(combo_has_flags&CHAS_MISC_WEAP_DATA)
9856 {
9857 if(auto ret = write_weap_data(tmp_cmb.misc_weap_data, f))
9858 return ret;
9859 }
9860 258906 return 0;
9861 258906 }
9862
9863 9 int32_t writecombos(PACKFILE *f, word version, word build, word start_combo, word max_combos)
9864 {
9865 //these are here to bypass compiler warnings about unused arguments
9866 9 version=version;
9867 9 build=build;
9868
9869 word combos_used;
9870 9 dword section_id=ID_COMBOS;
9871 9 dword section_version=V_COMBOS;
9872 // dword section_size=0;
9873 9 combos_used = count_combos()-start_combo;
9874
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, max_combos);
9875
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 combos_used = zc_min(combos_used, MAXCOMBOS);
9876 9 dword section_size = 0;
9877
9878 //section id
9879
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9880 {
9881 new_return(1);
9882 }
9883
9884 //section version info
9885
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9886 {
9887 new_return(2);
9888 }
9889
9890
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
9891 {
9892 new_return(3);
9893 }
9894
9895
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9896 {
9897 18 fake_pack_writing=(writecycle==0);
9898
9899 //section size
9900
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9901 {
9902 new_return(4);
9903 }
9904
9905 18 writesize=0;
9906
9907 //finally... section data
9908 18 combos_used=count_combos()-start_combo;
9909
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, max_combos);
9910
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 combos_used=zc_min(combos_used, MAXCOMBOS);
9911
9912
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(combos_used,f))
9913 {
9914 new_return(5);
9915 }
9916
9917 18 size_t end_combo = start_combo+combos_used;
9918
2/2
✓ Branch 0 taken 258906 times.
✓ Branch 1 taken 18 times.
258924 for(size_t q = start_combo; q < end_combo; ++q)
9919 {
9920 258906 auto ret = writecombo_loop(f, section_version, combobuf[q]);
9921
1/4
✓ Branch 0 taken 258906 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
258906 if(ret) new_return(ret);
9922 258906 }
9923
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
9924 {
9925 9 section_size=writesize;
9926 9 }
9927 18 }
9928
9929
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
9930 {
9931 char ebuf[80];
9932 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
9933 jwin_alert("Error: writecombos()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
9934 }
9935
9936 9 new_return(0);
9937 9 }
9938
9939 9 int32_t writecomboaliases(PACKFILE *f, word version, word build)
9940 {
9941 //these are here to bypass compiler warnings about unused arguments
9942 9 version=version;
9943 9 build=build;
9944
9945 9 dword section_id=ID_COMBOALIASES;
9946 9 dword section_version=V_COMBOALIASES;
9947 9 dword section_size=0;
9948
9949 //section id
9950
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
9951 {
9952 new_return(1);
9953 }
9954
9955 //section version info
9956
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
9957 {
9958 new_return(2);
9959 }
9960
9961
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
9962 {
9963 new_return(3);
9964 }
9965
9966
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
9967 {
9968 18 fake_pack_writing=(writecycle==0);
9969
9970 //section size
9971
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
9972 {
9973 new_return(4);
9974 }
9975
9976 18 writesize=0;
9977
9978 //finally... section data
9979
2/2
✓ Branch 0 taken 147456 times.
✓ Branch 1 taken 18 times.
147474 for(int32_t j=0; j<MAXCOMBOALIASES; j++)
9980 {
9981
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_iputw(combo_aliases[j].combo,f))
9982 {
9983 new_return(5);
9984 }
9985
9986
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].cset,f))
9987 {
9988 new_return(6);
9989 }
9990
9991 147456 int32_t count = ((combo_aliases[j].width+1)*(combo_aliases[j].height+1))*(comboa_lmasktotal(combo_aliases[j].layermask)+1);
9992
9993
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].width,f))
9994 {
9995 new_return(7);
9996 }
9997
9998
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].height,f))
9999 {
10000 new_return(8);
10001 }
10002
10003
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if(!p_putc(combo_aliases[j].layermask,f))
10004 {
10005 new_return(9);
10006 }
10007
10008
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10009 {
10010
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_iputw(combo_aliases[j].combos[k],f))
10011 {
10012 new_return(10);
10013 }
10014 149596 }
10015
10016
2/2
✓ Branch 0 taken 149596 times.
✓ Branch 1 taken 147456 times.
297052 for(int32_t k=0; k<count; k++)
10017 {
10018
1/2
✓ Branch 0 taken 149596 times.
✗ Branch 1 not taken.
149596 if(!p_putc(combo_aliases[j].csets[k],f))
10019 {
10020 new_return(11);
10021 }
10022 149596 }
10023 147456 }
10024
10025 //Combo pools!
10026 int16_t num_cpools;
10027
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 147452 times.
147468 for(num_cpools = MAXCOMBOPOOLS-1; num_cpools >= 0; --num_cpools)
10028 {
10029
2/2
✓ Branch 0 taken 147450 times.
✓ Branch 1 taken 2 times.
147452 if(combo_pools[num_cpools].valid()) //found a used pool
10030 {
10031 2 ++num_cpools;
10032 2 break;
10033 }
10034 147450 }
10035
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 16 times.
18 if(num_cpools < 0) num_cpools = 0;
10036
10037
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_cpools,f))
10038 {
10039 new_return(12);
10040 }
10041
10042
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 18 times.
24 for(auto cp = 0; cp < num_cpools; ++cp)
10043 {
10044 6 combo_pool const& pool = combo_pools[cp];
10045 6 int32_t num_combos = pool.combos.size();
10046
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(num_combos,f))
10047 {
10048 new_return(13);
10049 }
10050
10051
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 6 times.
32 for(auto q = 0; q < num_combos; ++q)
10052 {
10053 26 cpool_entry const& entry = pool.combos.at(q);
10054
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl(entry.cid,f))
10055 {
10056 new_return(14);
10057 }
10058
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_putc(entry.cset,f))
10059 {
10060 new_return(15);
10061 }
10062
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(entry.quant,f))
10063 {
10064 new_return(16);
10065 }
10066 26 }
10067 6 }
10068
10069 //Autocombos!
10070 int16_t num_cautos;
10071
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 147456 times.
147474 for (num_cautos = MAXAUTOCOMBOS - 1; num_cautos >= 0; --num_cautos)
10072 {
10073
1/2
✓ Branch 0 taken 147456 times.
✗ Branch 1 not taken.
147456 if (combo_autos[num_cautos].valid()) //found a used autocombo
10074 {
10075 ++num_cautos;
10076 break;
10077 }
10078 147456 }
10079
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if (num_cautos < 0) num_cautos = 0;
10080
10081
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(num_cautos, f))
10082 {
10083 new_return(17);
10084 }
10085
10086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for (auto ca = 0; ca < num_cautos; ++ca)
10087 {
10088 combo_auto const& cauto = combo_autos[ca];
10089 if (!p_putc(cauto.getType(), f))
10090 {
10091 new_return(18);
10092 }
10093 if (!p_iputl(cauto.getIconDisplay(), f))
10094 {
10095 new_return(19);
10096 }
10097 if (!p_iputl(cauto.getEraseCombo(), f))
10098 {
10099 new_return(20);
10100 }
10101 if (!p_putc(cauto.getFlags(), f))
10102 {
10103 new_return(21);
10104 }
10105 if (!p_putc(cauto.getArg(), f))
10106 {
10107 new_return(22);
10108 }
10109 int32_t num_combos = cauto.combos.size();
10110 if (!p_iputl(num_combos, f))
10111 {
10112 new_return(23);
10113 }
10114
10115 for (auto q = 0; q < num_combos; ++q)
10116 {
10117 autocombo_entry const& entry = cauto.combos.at(q);
10118 if (!p_putc(entry.ctype, f))
10119 {
10120 new_return(24);
10121 }
10122 if (!p_iputl(entry.cid, f))
10123 {
10124 new_return(25);
10125 }
10126 }
10127 }
10128
10129
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10130 {
10131 9 section_size=writesize;
10132 9 }
10133 18 }
10134
10135
10136
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10137 {
10138 char ebuf[80];
10139 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10140 jwin_alert("Error: writecomboaliases()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10141 }
10142
10143 9 new_return(0);
10144 }
10145
10146 9 int32_t writecolordata(PACKFILE *f, word version, word build, word start_cset, word max_csets)
10147 {
10148 //these are here to bypass compiler warnings about unused arguments
10149 9 version=version;
10150 9 build=build;
10151 9 start_cset=start_cset;
10152 9 max_csets=max_csets;
10153
10154 9 dword section_id=ID_CSETS;
10155 9 dword section_version=V_CSETS;
10156 9 int32_t palcycles = count_palcycles(&QMisc);
10157 // int32_t palcyccount = count_palcycles(&QMisc);
10158 9 dword section_size = 0;
10159
10160 //section id
10161
10162
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10163 {
10164 new_return(1);
10165 }
10166
10167 //section version info
10168
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10169 {
10170 new_return(2);
10171 }
10172
10173
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10174 {
10175 new_return(3);
10176 }
10177
10178
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10179 {
10180 18 fake_pack_writing=(writecycle==0);
10181
10182 //section size
10183
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10184 {
10185 new_return(4);
10186 }
10187
10188 18 writesize=0;
10189
10190 //finally... section data
10191
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(colordata,psTOTAL255,f))
10192 {
10193 new_return(5);
10194 }
10195
10196
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(palnames,MAXLEVELS*PALNAMESIZE,f))
10197 {
10198 new_return(6);
10199 }
10200
10201
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(palcycles,f))
10202 {
10203 new_return(15);
10204 }
10205
10206
2/2
✓ Branch 0 taken 550 times.
✓ Branch 1 taken 18 times.
568 for(int32_t i=0; i<palcycles; i++)
10207 {
10208
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10209 {
10210
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].first,f))
10211 {
10212 new_return(16);
10213 }
10214 1650 }
10215
10216
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10217 {
10218
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].count,f))
10219 {
10220 new_return(17);
10221 }
10222 1650 }
10223
10224
2/2
✓ Branch 0 taken 1650 times.
✓ Branch 1 taken 550 times.
2200 for(int32_t j=0; j<3; j++)
10225 {
10226
1/2
✓ Branch 0 taken 1650 times.
✗ Branch 1 not taken.
1650 if(!p_putc(QMisc.cycles[i][j].speed,f))
10227 {
10228 new_return(18);
10229 }
10230 1650 }
10231 550 }
10232
10233
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10234 {
10235 9 section_size=writesize;
10236 9 }
10237 18 }
10238
10239
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10240 {
10241 char ebuf[80];
10242 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10243 jwin_alert("Error: writecolordata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10244 }
10245
10246 9 new_return(0);
10247 }
10248
10249 9 int32_t writestrings(PACKFILE *f, word version, word build, word start_msgstr, word max_msgstrs)
10250 {
10251 //these are here to bypass compiler warnings about unused arguments
10252 9 version=version;
10253 9 build=build;
10254 9 start_msgstr=start_msgstr;
10255 9 max_msgstrs=max_msgstrs;
10256
10257 9 dword section_id=ID_STRINGS;
10258 9 dword section_version=V_STRINGS;
10259 9 dword section_size = 0;
10260
10261 //section id
10262
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10263 {
10264 new_return(1);
10265 }
10266
10267 //section version info
10268
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10269 {
10270 new_return(2);
10271 }
10272
10273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10274 {
10275 new_return(3);
10276 }
10277
10278
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10279 {
10280 18 fake_pack_writing=(writecycle==0);
10281
10282 //section size
10283
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10284 {
10285 new_return(4);
10286 }
10287
10288 18 writesize=0;
10289
10290 //finally... section data
10291
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(msg_count,f))
10292 {
10293 return qe_invalid;
10294 }
10295
10296
2/2
✓ Branch 0 taken 836 times.
✓ Branch 1 taken 18 times.
854 for(int32_t i=0; i<msg_count; i++)
10297 {
10298 836 MsgStrings[i].ensureAsciiEncoding();
10299 836 int32_t sz = MsgStrings[i].s.size();
10300
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(sz > 8192) sz = 8192;
10301
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(sz, f))
10302 {
10303 return qe_invalid;
10304 }
10305
10306 836 char const* tmpstr = MsgStrings[i].s.c_str();
10307
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 836 times.
836 if (sz > 0)
10308 {
10309
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if (!pfwrite((void*)tmpstr,sz, f))
10310 {
10311 return qe_invalid;
10312 }
10313 836 }
10314
10315
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].nextstring,f))
10316 {
10317 return qe_invalid;
10318 }
10319
10320
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].tile,f))
10321 {
10322 return qe_invalid;
10323 }
10324
10325
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].cset,f))
10326 {
10327 return qe_invalid;
10328 }
10329
10330
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].trans?1:0,f))
10331 {
10332 return qe_invalid;
10333 }
10334
10335
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].font,f))
10336 {
10337 return qe_invalid;
10338 }
10339
10340
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].x,f))
10341 {
10342 return qe_invalid;
10343 }
10344
10345
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].y,f))
10346 {
10347 return qe_invalid;
10348 }
10349
10350
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].w,f))
10351 {
10352 return qe_invalid;
10353 }
10354
10355
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].h,f))
10356 {
10357 return qe_invalid;
10358 }
10359
10360
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].hspace,f))
10361 {
10362 return qe_invalid;
10363 }
10364
10365
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].vspace,f))
10366 {
10367 return qe_invalid;
10368 }
10369
10370
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].stringflags,f))
10371 {
10372 return qe_invalid;
10373 }
10374
10375
2/2
✓ Branch 0 taken 3344 times.
✓ Branch 1 taken 836 times.
4180 for(int32_t q = 0; q < 4; ++q)
10376 {
10377
1/2
✓ Branch 0 taken 3344 times.
✗ Branch 1 not taken.
3344 if(!p_putc(MsgStrings[i].margins[q],f))
10378 {
10379 return qe_invalid;
10380 }
10381 3344 }
10382
10383
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputl(MsgStrings[i].portrait_tile,f))
10384 {
10385 return qe_invalid;
10386 }
10387
10388
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_cset,f))
10389 {
10390 return qe_invalid;
10391 }
10392
10393
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_x,f))
10394 {
10395 return qe_invalid;
10396 }
10397
10398
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_y,f))
10399 {
10400 return qe_invalid;
10401 }
10402
10403
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_tw,f))
10404 {
10405 return qe_invalid;
10406 }
10407
10408
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].portrait_th,f))
10409 {
10410 return qe_invalid;
10411 }
10412
10413
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_type,f))
10414 {
10415 return qe_invalid;
10416 }
10417
10418
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].shadow_color,f))
10419 {
10420 return qe_invalid;
10421 }
10422
10423
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].drawlayer,f))
10424 {
10425 return qe_invalid;
10426 }
10427
10428
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_putc(MsgStrings[i].sfx,f))
10429 {
10430 return qe_invalid;
10431 }
10432
10433
1/2
✓ Branch 0 taken 836 times.
✗ Branch 1 not taken.
836 if(!p_iputw(MsgStrings[i].listpos,f))
10434 {
10435 return qe_invalid;
10436 }
10437 836 }
10438
10439
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10440 {
10441 9 section_size=writesize;
10442 9 }
10443 18 }
10444
10445
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10446 {
10447 char ebuf[80];
10448 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10449 jwin_alert("Error: writestrings()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10450 }
10451
10452 9 new_return(0);
10453 9 }
10454
10455 int32_t writestrings_text(PACKFILE *f)
10456 {
10457 std::map<int32_t, int32_t> msglistcache;
10458
10459 for(int32_t index = 1; index<msg_count; index++)
10460 {
10461 for(int32_t i=1; i<msg_count; i++)
10462 {
10463 if(MsgStrings[i].listpos==index)
10464 {
10465 msglistcache[index-1]=i;
10466 break;
10467 }
10468 }
10469 }
10470
10471 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10472 {
10473 fake_pack_writing=(writecycle==0);
10474 char ebuf[32];
10475
10476 sprintf(ebuf,"Total strings: %d\n", msg_count-1);
10477
10478 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10479 {
10480 return qe_invalid;
10481 }
10482
10483 for(int32_t i=1; i<msg_count; i++)
10484 {
10485 int32_t str = msglistcache[i-1];
10486
10487 if(!str)
10488 continue;
10489
10490 if(MsgStrings[str].nextstring != 0)
10491 sprintf(ebuf,"\n\n___%d(->%d)___\n", str,MsgStrings[str].nextstring);
10492 else
10493 sprintf(ebuf,"\n\n___%d___\n", str);
10494
10495 if(!pfwrite(&ebuf,(int32_t)strlen(ebuf),f))
10496 {
10497 return qe_invalid;
10498 }
10499
10500 std::string text = MsgStrings[str].serialize();
10501 if (!pfwrite(text.c_str(), text.size(), f))
10502 {
10503 return qe_invalid;
10504 }
10505 }
10506 }
10507
10508 new_return(0);
10509 }
10510
10511 1 int32_t writestrings_tsv(PACKFILE *f)
10512 {
10513 1 std::stringstream ss;
10514
10515
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::vector<std::pair<std::string, std::function<std::string(const MsgStr&)>>> fields = {
10516
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "message", [&](auto& msg){ return msg.serialize(); }},
10517
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "next", [](auto& msg){ return std::to_string(msg.nextstring); } },
10518
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "tile", [](auto& msg){ return std::to_string(msg.tile); } },
10519
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "cset", [](auto& msg){ return std::to_string(msg.cset); } },
10520
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "trans", [](auto& msg){ return std::to_string(msg.trans); } },
10521
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "font", [](auto& msg){ return std::to_string(msg.font); } },
10522
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "x", [](auto& msg){ return std::to_string(msg.x); } },
10523
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "y", [](auto& msg){ return std::to_string(msg.y); } },
10524
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "w", [](auto& msg){ return std::to_string(msg.w); } },
10525
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "h", [](auto& msg){ return std::to_string(msg.h); } },
10526
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "sfx", [](auto& msg){ return std::to_string(msg.sfx); } },
10527
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "pos", [](auto& msg){ return std::to_string(msg.listpos); } },
10528
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "vspace", [](auto& msg){ return std::to_string(msg.vspace); } },
10529
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "hspace", [](auto& msg){ return std::to_string(msg.hspace); } },
10530
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "flags", [](auto& msg){ return std::to_string(msg.stringflags); } },
10531
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "margin", [](auto& msg){ return fmt::format("{} {} {} {}", msg.margins[0], msg.margins[3], msg.margins[1], msg.margins[2]); } },
10532
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tile", [](auto& msg){ return std::to_string(msg.portrait_tile); } },
10533
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_cset", [](auto& msg){ return std::to_string(msg.portrait_cset); } },
10534
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_x", [](auto& msg){ return std::to_string(msg.portrait_x); } },
10535
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_y", [](auto& msg){ return std::to_string(msg.portrait_y); } },
10536
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_tw", [](auto& msg){ return std::to_string(msg.portrait_tw); } },
10537
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "portrait_th", [](auto& msg){ return std::to_string(msg.portrait_th); } },
10538
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_type", [](auto& msg){ return std::to_string(msg.shadow_type); } },
10539
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "shadow_color", [](auto& msg){ return std::to_string(msg.shadow_color); } },
10540
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
36 { "drawlayer", [](auto& msg){ return std::to_string(msg.drawlayer); } },
10541 };
10542
10543
1/2
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
25 for (auto& [name, fn] : fields)
10544 {
10545
2/4
✓ Branch 0 taken 25 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 25 times.
✗ Branch 3 not taken.
50 ss << name;
10546
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 1 times.
25 if (name == fields.back().first)
10547 1 break;
10548
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 ss << '\t';
10549 }
10550
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << '\n';
10551
10552 // First entry is a fake string, to help frame the lines. Should be helpful if manually editing these in a text editor or spreadsheet.
10553
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 ss << "|IT'S DANGEROUS TO GO || ALONE! TAKE THIS. ||LOREM IPSUM LOREM IPSU|\n";
10554
10555
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 35 times.
36 for(int32_t i=1; i<msg_count; i++)
10556 {
10557 35 auto& msg = MsgStrings[i];
10558
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
1750 for (auto& [name, fn] : fields)
10559 {
10560
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 std::string text = fn(msg);
10561
1/2
✓ Branch 0 taken 875 times.
✗ Branch 1 not taken.
875 ss << text;
10562
2/2
✓ Branch 0 taken 840 times.
✓ Branch 1 taken 35 times.
875 if (name == fields.back().first)
10563 35 break;
10564
1/2
✓ Branch 0 taken 840 times.
✗ Branch 1 not taken.
840 ss << '\t';
10565
2/3
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 840 times.
875 }
10566
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 ss << '\n';
10567 35 }
10568
10569
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 std::string text = ss.str();
10570
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!pack_fwrite(text.c_str(), text.size(), f))
10571 {
10572 return qe_invalid;
10573 }
10574
10575 1 new_return(0);
10576 1 }
10577
10578 void parse_strings_tsv(std::string tsv)
10579 {
10580 std::map<std::string, std::function<void(MsgStr&, const std::string&)>> fields = {
10581 { "message", [](auto& msg, auto& text){ msg.setFromAsciiEncoding(text); } },
10582 { "next", [](auto& msg, auto& text){ msg.nextstring = std::stoi(text); } },
10583 { "tile", [](auto& msg, auto& text){ msg.tile = std::stoi(text); } },
10584 { "cset", [](auto& msg, auto& text){ msg.cset = std::stoi(text); } },
10585 { "trans", [](auto& msg, auto& text){ msg.trans = std::stoi(text); } },
10586 { "font", [](auto& msg, auto& text){ msg.font = std::stoi(text); } },
10587 { "x", [](auto& msg, auto& text){ msg.x = std::stoi(text); } },
10588 { "y", [](auto& msg, auto& text){ msg.y = std::stoi(text); } },
10589 { "w", [](auto& msg, auto& text){ msg.w = std::stoi(text); } },
10590 { "h", [](auto& msg, auto& text){ msg.h = std::stoi(text); } },
10591 { "sfx", [](auto& msg, auto& text){ msg.sfx = std::stoi(text); } },
10592 { "pos", [](auto& msg, auto& text){ msg.listpos = std::stoi(text); } },
10593 { "vspace", [](auto& msg, auto& text){ msg.vspace = std::stoi(text); } },
10594 { "hspace", [](auto& msg, auto& text){ msg.hspace = std::stoi(text); } },
10595 { "flags", [](auto& msg, auto& text){ msg.stringflags = std::stoi(text); } },
10596 { "margin", [&](auto& msg, auto& text){
10597 std::vector<std::string> strs;
10598 util::split(text, strs, ' ');
10599 if (strs.size() != 4)
10600 throw std::runtime_error("margin field must have 4 components");
10601 msg.margins[0] = std::stoi(strs[0]);
10602 msg.margins[1] = std::stoi(strs[1]);
10603 msg.margins[2] = std::stoi(strs[2]);
10604 msg.margins[3] = std::stoi(strs[3]);
10605 } },
10606 { "portrait_tile", [](auto& msg, auto& text){ msg.portrait_tile = std::stoi(text); } },
10607 { "portrait_cset", [](auto& msg, auto& text){ msg.portrait_cset = std::stoi(text); } },
10608 { "portrait_x", [](auto& msg, auto& text){ msg.portrait_x = std::stoi(text); } },
10609 { "portrait_y", [](auto& msg, auto& text){ msg.portrait_y = std::stoi(text); } },
10610 { "portrait_tw", [](auto& msg, auto& text){ msg.portrait_tw = std::stoi(text); } },
10611 { "portrait_th", [](auto& msg, auto& text){ msg.portrait_th = std::stoi(text); } },
10612 { "shadow_type", [](auto& msg, auto& text){ msg.shadow_type = std::stoi(text); } },
10613 { "shadow_color", [](auto& msg, auto& text){ msg.shadow_color = std::stoi(text); } },
10614 { "drawlayer", [](auto& msg, auto& text){ msg.drawlayer = std::stoi(text); } },
10615 };
10616
10617 std::vector<std::string> rows;
10618 util::split(tsv, rows, '\n');
10619 if (rows.size())
10620 {
10621 std::string last = rows.back();
10622 util::trimstr(last);
10623 if (last.empty())
10624 rows.pop_back();
10625 }
10626 if (rows.size() <= 1)
10627 throw std::runtime_error("missing header row");
10628
10629 std::vector<std::string> columns;
10630 util::split(rows[0], columns, '\t');
10631 for (auto name : columns)
10632 {
10633 if (!fields.contains(name))
10634 throw std::runtime_error(fmt::format("invalid field: {}", name));
10635 }
10636
10637 int start_index = 1;
10638 if (rows[start_index].find("||LOREM IPSUM") != std::string::npos)
10639 start_index += 1;
10640
10641 int num_strings = rows.size() - start_index + 1;
10642 if (num_strings > MAXMSGS-1)
10643 throw std::runtime_error(fmt::format("too many strings, max is {}", MAXMSGS-1));
10644
10645 std::vector<MsgStr> msgs;
10646 msgs.reserve(num_strings);
10647 for (int i = start_index; i < rows.size(); i++)
10648 {
10649 std::vector<std::string> strs;
10650 util::split(rows[i], strs, '\t');
10651 if (strs.size() != columns.size())
10652 throw std::runtime_error(fmt::format("row {} has {} fields, expected {}", i, strs.size(), columns.size()));
10653
10654 int j = 0;
10655 auto& msg = msgs.emplace_back();
10656 for (auto& name : columns)
10657 {
10658 auto& fn = fields[name];
10659 try
10660 {
10661 fn(msg, strs[j++]);
10662 }
10663 catch (std::exception& ex)
10664 {
10665 throw std::runtime_error(fmt::format("error parsing row {} field {}: {}", i, name, ex.what()));
10666 }
10667 }
10668 }
10669
10670 init_msgstrings(0, msgs.size());
10671 for (int i = 0; i < msgs.size(); i++)
10672 MsgStrings[i + 1] = msgs[i];
10673 msg_count = msgs.size() + 1;
10674 msglistcache.clear();
10675 }
10676
10677 bool isblanktile(tiledata *buf, int32_t i);
10678 9 int32_t writetiles(PACKFILE *f, word version, word build, int32_t start_tile, int32_t max_tiles)
10679 {
10680 //these are here to bypass compiler warnings about unused arguments
10681 9 version=version;
10682 9 build=build;
10683
10684 int32_t tiles_used;
10685 9 dword section_id=ID_TILES;
10686 9 dword section_version=V_TILES;
10687 9 al_trace("Counting tiles used\n");
10688 9 tiles_used = count_tiles(newtilebuf)-start_tile;
10689
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, max_tiles);
10690
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 tiles_used = zc_min(tiles_used, NEWMAXTILES);
10691 9 al_trace("writetiles counted %dtiles used.\n",tiles_used);
10692 9 dword section_size = 0;
10693
10694 //section id
10695
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10696 {
10697 new_return(1);
10698 }
10699
10700 //section version info
10701
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10702 {
10703 new_return(2);
10704 }
10705
10706
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10707 {
10708 new_return(3);
10709 }
10710
10711
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10712 {
10713 18 fake_pack_writing=(writecycle==0);
10714
10715 //section size
10716
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10717 {
10718 new_return(4);
10719 }
10720
10721 18 writesize=0;
10722
10723 //finally... section data
10724 18 tiles_used=count_tiles(newtilebuf)-start_tile;
10725
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, max_tiles);
10726
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 tiles_used=zc_min(tiles_used, NEWMAXTILES);
10727
10728
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(tiles_used,f))
10729 {
10730 new_return(5);
10731 }
10732
10733
2/2
✓ Branch 0 taken 696384 times.
✓ Branch 1 taken 18 times.
696402 for(int32_t i=0; i<tiles_used; ++i)
10734 {
10735
2/2
✓ Branch 0 taken 365770 times.
✓ Branch 1 taken 330614 times.
696384 if(isblanktile(newtilebuf, start_tile+i))
10736 {
10737
1/2
✓ Branch 0 taken 365770 times.
✗ Branch 1 not taken.
365770 if(!p_putc(0,f))
10738 new_return(8);
10739 365770 }
10740 else
10741 {
10742 330614 int format = newtilebuf[start_tile+i].format;
10743
1/2
✓ Branch 0 taken 330614 times.
✗ Branch 1 not taken.
330614 if(!p_putc(format,f))
10744 {
10745 new_return(6);
10746 }
10747
10748
2/2
✓ Branch 0 taken 327742 times.
✓ Branch 1 taken 2872 times.
330614 if (format == tf4Bit)
10749 {
10750 byte temp_tile[128];
10751 327742 byte *di = temp_tile;
10752 327742 byte *src = newtilebuf[start_tile+i].data;
10753
2/2
✓ Branch 0 taken 41950976 times.
✓ Branch 1 taken 327742 times.
42278718 for (int32_t si=0; si<256; si+=2)
10754 {
10755 41950976 *di = (src[si]&15) + ((src[si+1]&15) << 4);
10756 41950976 ++di;
10757 41950976 }
10758
1/2
✓ Branch 0 taken 327742 times.
✗ Branch 1 not taken.
327742 if (!pfwrite(temp_tile,128,f))
10759 {
10760 new_return(7);
10761 }
10762 327742 }
10763
1/2
✓ Branch 0 taken 2872 times.
✗ Branch 1 not taken.
2872 else if (!pfwrite(newtilebuf[start_tile+i].data,tilesize(format),f))
10764 {
10765 new_return(7);
10766 }
10767 }
10768 696384 }
10769
10770
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10771 {
10772 9 section_size=writesize;
10773 9 }
10774 18 }
10775
10776
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10777 {
10778 char ebuf[80];
10779 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10780 jwin_alert("Error: writetiles()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10781 }
10782
10783 9 new_return(0);
10784 }
10785
10786 /* MIDI Format
10787 section_id LONG
10788 section_version WORD
10789 section_cversion WORD
10790 section_size LONG
10791 midi_flags 32 Byte ? BITFIELD[252]
10792
10793 [
10794 title 36
10795 start 4
10796 loop_start 4
10797 loop_end 4
10798 loop 2
10799 volume 2
10800 midi *
10801 ]
10802
10803 */
10804
10805 9 int32_t writemidis(PACKFILE *f)
10806 {
10807 9 dword section_id=ID_MIDIS;
10808 9 dword section_version=V_MIDIS;
10809 9 dword section_size = 0;
10810
10811 //section id
10812
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10813 {
10814 new_return(1);
10815 }
10816
10817 //section version info
10818
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10819 {
10820 new_return(2);
10821 }
10822
10823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10824 {
10825 new_return(3);
10826 }
10827
10828
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10829 {
10830 18 fake_pack_writing=(writecycle==0);
10831
10832 //section size
10833
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10834 {
10835 new_return(4);
10836 }
10837
10838 18 writesize=0;
10839
10840 //finally... section data
10841
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(midi_flags,sizeof(midi_flags),f))
10842 {
10843 new_return(5);
10844 }
10845
10846
2/2
✓ Branch 0 taken 4536 times.
✓ Branch 1 taken 18 times.
4554 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
10847 {
10848
2/2
✓ Branch 0 taken 4406 times.
✓ Branch 1 taken 130 times.
4536 if(get_bit(midi_flags,i))
10849 {
10850
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].title,sizeof(customtunes[0].title)-1,f))
10851 {
10852 new_return(6);
10853 }
10854
10855
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].start,f))
10856 {
10857 new_return(7);
10858 }
10859
10860
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_start,f))
10861 {
10862 new_return(8);
10863 }
10864
10865
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputl(customtunes[i].loop_end,f))
10866 {
10867 new_return(9);
10868 }
10869
10870
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].loop,f))
10871 {
10872 new_return(10);
10873 }
10874
10875
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!p_iputw(customtunes[i].volume,f))
10876 {
10877 new_return(11);
10878 }
10879
10880
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&customtunes[i].flags, sizeof(customtunes[i].flags),f))
10881 {
10882 new_return(12);
10883 }
10884
10885 130 byte format = MFORMAT_MIDI;
10886
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if(!pfwrite(&format, sizeof(format),f))
10887 {
10888 new_return(13);
10889 }
10890
10891
1/2
✓ Branch 0 taken 130 times.
✗ Branch 1 not taken.
130 if (!write_midi(customtunes[i].data, f)) new_return(14);
10892 130 }
10893 4536 }
10894
10895
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10896 {
10897 9 section_size=writesize;
10898 9 }
10899 18 }
10900
10901
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10902 {
10903 char ebuf[80];
10904 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10905 jwin_alert("Error: writemidis()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10906 }
10907
10908 9 new_return(0);
10909 }
10910
10911 9 int32_t writecheats(PACKFILE *f, zquestheader *Header)
10912 {
10913 9 dword section_id=ID_CHEATS;
10914 9 dword section_version=V_CHEATS;
10915 9 dword section_size = 0;
10916
10917 //section id
10918
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10919 {
10920 new_return(1);
10921 }
10922
10923 //section version info
10924
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10925 {
10926 new_return(2);
10927 }
10928
10929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
10930 {
10931 new_return(3);
10932 }
10933
10934
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
10935 {
10936 18 fake_pack_writing=(writecycle==0);
10937
10938 //section size
10939
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
10940 {
10941 new_return(4);
10942 }
10943
10944 18 writesize=0;
10945
10946 //finally... section data
10947
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(Header->data_flags[ZQ_CHEATS2],f))
10948 {
10949 new_return(5);
10950 }
10951
10952
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 if(Header->data_flags[ZQ_CHEATS2])
10953 {
10954
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zcheats.flags,f))
10955 {
10956 new_return(6);
10957 }
10958
10959
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite(&zcheats.codes, sizeof(zcheats.codes), f))
10960 {
10961 new_return(7);
10962 }
10963 18 }
10964
10965
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
10966 {
10967 9 section_size=writesize;
10968 9 }
10969 18 }
10970
10971
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
10972 {
10973 char ebuf[80];
10974 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
10975 jwin_alert("Error: writecheats()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
10976 }
10977
10978 9 new_return(0);
10979 }
10980
10981 9 int32_t writeguys(PACKFILE *f, zquestheader *Header)
10982 {
10983 //these are here to bypass compiler warnings about unused arguments
10984 9 Header=Header;
10985
10986 9 dword section_id=ID_GUYS;
10987 9 dword section_version=V_GUYS;
10988 9 dword section_size=0;
10989
10990 //section id
10991
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
10992 {
10993 new_return(1);
10994 }
10995
10996 //section version info
10997
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
10998 {
10999 new_return(2);
11000 }
11001
11002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11003 {
11004 new_return(3);
11005 }
11006
11007
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11008 {
11009 18 fake_pack_writing=(writecycle==0);
11010
11011 //section size
11012
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11013 {
11014 new_return(4);
11015 }
11016
11017 18 writesize=0;
11018
11019 //finally... section data
11020
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11021 {
11022
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!pfwrite((char *)guy_string[i], 64, f))
11023 {
11024 new_return(5);
11025 }
11026 9216 }
11027
11028
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int32_t i=0; i<MAXGUYS; i++)
11029 {
11030 9216 uint32_t flags1 = uint32_t(guysbuf[i].flags);
11031 9216 uint32_t flags2 = uint32_t(guysbuf[i].flags >> 32ULL);
11032
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags1, f))
11033 {
11034 new_return(6);
11035 }
11036
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_iputl(flags2, f))
11037 {
11038 new_return(7);
11039 }
11040
11041
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tile,f))
11042 {
11043 new_return(8);
11044 }
11045
11046
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].width,f))
11047 {
11048 new_return(9);
11049 }
11050
11051
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].height,f))
11052 {
11053 new_return(10);
11054 }
11055
11056
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].s_tile,f))
11057 {
11058 new_return(11);
11059 }
11060
11061
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_width,f))
11062 {
11063 new_return(12);
11064 }
11065
11066
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].s_height,f))
11067 {
11068 new_return(13);
11069 }
11070
11071
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].e_tile,f))
11072 {
11073 new_return(14);
11074 }
11075
11076
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_width,f))
11077 {
11078 new_return(15);
11079 }
11080
11081
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].e_height,f))
11082 {
11083 new_return(16);
11084 }
11085
11086
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hp,f))
11087 {
11088 new_return(17);
11089 }
11090
11091
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].type,f))
11092 {
11093 new_return(18);
11094 }
11095
11096
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].cset,f))
11097 {
11098 new_return(19);
11099 }
11100
11101
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].anim,f))
11102 {
11103 new_return(20);
11104 }
11105
11106
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_anim,f))
11107 {
11108 new_return(21);
11109 }
11110
11111
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].frate,f))
11112 {
11113 new_return(22);
11114 }
11115
11116
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].e_frate,f))
11117 {
11118 new_return(23);
11119 }
11120
11121
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].dp,f))
11122 {
11123 new_return(24);
11124 }
11125
11126
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].wdp,f))
11127 {
11128 new_return(25);
11129 }
11130
11131
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].weapon,f))
11132 {
11133 new_return(26);
11134 }
11135
11136
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].rate,f))
11137 {
11138 new_return(27);
11139 }
11140
11141
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].hrate,f))
11142 {
11143 new_return(28);
11144 }
11145
11146
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].step,f))
11147 {
11148 new_return(29);
11149 }
11150
11151
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].homing,f))
11152 {
11153 new_return(30);
11154 }
11155
11156
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].grumble,f))
11157 {
11158 new_return(31);
11159 }
11160
11161
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].item_set,f))
11162 {
11163 new_return(32);
11164 }
11165
11166
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[0], f))
11167 {
11168 new_return(33);
11169 }
11170
11171
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[1],f))
11172 {
11173 new_return(34);
11174 }
11175
11176
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[2],f))
11177 {
11178 new_return(35);
11179 }
11180
11181
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[3],f))
11182 {
11183 new_return(36);
11184 }
11185
11186
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[4],f))
11187 {
11188 new_return(37);
11189 }
11190
11191
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[5],f))
11192 {
11193 new_return(38);
11194 }
11195
11196
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[6],f))
11197 {
11198 new_return(39);
11199 }
11200
11201
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[7],f))
11202 {
11203 new_return(40);
11204 }
11205
11206
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[8],f))
11207 {
11208 new_return(41);
11209 }
11210
11211
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[9],f))
11212 {
11213 new_return(42);
11214 }
11215
11216
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bgsfx,f))
11217 {
11218 new_return(43);
11219 }
11220
11221
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].bosspal,f))
11222 {
11223 new_return(44);
11224 }
11225
11226
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].extend,f))
11227 {
11228 new_return(45);
11229 }
11230
11231
2/2
✓ Branch 0 taken 175104 times.
✓ Branch 1 taken 9216 times.
184320 for(int32_t j=0; j < edefLAST; j++)
11232 {
11233
1/2
✓ Branch 0 taken 175104 times.
✗ Branch 1 not taken.
175104 if(!p_putc(guysbuf[i].defense[j],f))
11234 {
11235 new_return(46);
11236 }
11237 175104 }
11238
11239
5/6
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6144 times.
✓ Branch 3 taken 3072 times.
✓ Branch 4 taken 2048 times.
✓ Branch 5 taken 4096 times.
9216 if ( FFCore.getQuestHeaderInfo(vZelda) < 0x250 || (( FFCore.getQuestHeaderInfo(vZelda) == 0x250 ) && FFCore.getQuestHeaderInfo(vBuild) < 32 ) )
11240 {
11241 //If no user-set hit sound was in place, and the quest was made in a version before 2.53.0 Gamma 2:
11242
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2048 times.
2048 if ( guysbuf[i].hitsfx == 0 ) guysbuf[i].hitsfx = WAV_EHIT; //Fix quests using the wrong hit sound when loading this.
11243 //Force SFX_HIT here.
11244
11245 2048 }
11246
11247
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].hitsfx,f))
11248 {
11249 new_return(47);
11250 }
11251
11252
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].deadsfx,f))
11253 {
11254 new_return(48);
11255 }
11256
11257
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[10],f))
11258 {
11259 new_return(49);
11260 }
11261
11262
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[11],f))
11263 {
11264 new_return(50);
11265 }
11266
11267 //New 2.6 defences
11268
2/2
✓ Branch 0 taken 202752 times.
✓ Branch 1 taken 9216 times.
211968 for(int32_t j=edefLAST; j < edefLAST255; j++)
11269 {
11270
1/2
✓ Branch 0 taken 202752 times.
✗ Branch 1 not taken.
202752 if(!p_putc(guysbuf[i].defense[j],f))
11271 {
11272 new_return(51);
11273 }
11274 202752 }
11275
11276 //tilewidth, tileheight, hitwidth, hitheight, hitzheight, hitxofs, hityofs, hitzofs
11277
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].txsz,f))
11278 {
11279 new_return(52);
11280 }
11281
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].tysz,f))
11282 {
11283 new_return(53);
11284 }
11285
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxsz,f))
11286 {
11287 new_return(54);
11288 }
11289
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hysz,f))
11290 {
11291 new_return(55);
11292 }
11293
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hzsz,f))
11294 {
11295 new_return(56);
11296 }
11297 // These are not fixed types, but ints, so they are safe to use here.
11298
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hxofs,f))
11299 {
11300 new_return(57);
11301 }
11302
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].hyofs,f))
11303 {
11304 new_return(58);
11305 }
11306
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].xofs,f))
11307 {
11308 new_return(59);
11309 }
11310
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].yofs,f))
11311 {
11312 new_return(60);
11313 }
11314
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].zofs,f))
11315 {
11316 new_return(61);
11317 }
11318
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].wpnsprite,f))
11319 {
11320 new_return(62);
11321 }
11322
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].SIZEflags,f))
11323 {
11324 new_return(63);
11325 }
11326
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozentile,f))
11327 {
11328 new_return(64);
11329 }
11330
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozencset,f))
11331 {
11332 new_return(65);
11333 }
11334
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].frozenclock,f))
11335 {
11336 new_return(66);
11337 }
11338
11339
2/2
✓ Branch 0 taken 92160 times.
✓ Branch 1 taken 9216 times.
101376 for ( int32_t q = 0; q < 10; q++ )
11340 {
11341
1/2
✓ Branch 0 taken 92160 times.
✗ Branch 1 not taken.
92160 if(!p_iputw(guysbuf[i].frozenmisc[q],f))
11342 {
11343 new_return(67);
11344 }
11345 92160 }
11346
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].firesfx,f))
11347 {
11348 new_return(68);
11349 }
11350 //misc 16->31
11351
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[15],f))
11352 {
11353 new_return(69);
11354 }
11355
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[16],f))
11356 {
11357 new_return(70);
11358 }
11359
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[17],f))
11360 {
11361 new_return(71);
11362 }
11363
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[18],f))
11364 {
11365 new_return(72);
11366 }
11367
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[19],f))
11368 {
11369 new_return(73);
11370 }
11371
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[20],f))
11372 {
11373 new_return(74);
11374 }
11375
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[21],f))
11376 {
11377 new_return(75);
11378 }
11379
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[22],f))
11380 {
11381 new_return(76);
11382 }
11383
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[23],f))
11384 {
11385 new_return(77);
11386 }
11387
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[24],f))
11388 {
11389 new_return(78);
11390 }
11391
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[25],f))
11392 {
11393 new_return(79);
11394 }
11395
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[26],f))
11396 {
11397 new_return(80);
11398 }
11399
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[27],f))
11400 {
11401 new_return(81);
11402 }
11403
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[28],f))
11404 {
11405 new_return(82);
11406 }
11407
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[29],f))
11408 {
11409 new_return(83);
11410 }
11411
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[30],f))
11412 {
11413 new_return(84);
11414 }
11415
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[31],f))
11416 {
11417 new_return(85);
11418 }
11419
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11420 {
11421
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].movement[q],f))
11422 {
11423 new_return(86);
11424 }
11425 294912 }
11426
2/2
✓ Branch 0 taken 294912 times.
✓ Branch 1 taken 9216 times.
304128 for ( int32_t q = 0; q < 32; q++ )
11427 {
11428
1/2
✓ Branch 0 taken 294912 times.
✗ Branch 1 not taken.
294912 if(!p_iputl(guysbuf[i].new_weapon[q],f))
11429 {
11430 new_return(87);
11431 }
11432 294912 }
11433
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(guysbuf[i].script,f))
11434 {
11435 new_return(88);
11436 }
11437
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11438 {
11439
1/2
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
73728 if(!p_iputl(guysbuf[i].initD[q],f))
11440 {
11441 new_return(89);
11442 }
11443 73728 }
11444
2/2
✓ Branch 0 taken 18432 times.
✓ Branch 1 taken 9216 times.
27648 for ( int32_t q = 0; q < 2; q++ )
11445 {
11446
1/2
✓ Branch 0 taken 18432 times.
✗ Branch 1 not taken.
18432 if(!p_iputl(0,f))
11447 {
11448 new_return(90);
11449 }
11450 18432 }
11451
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].editorflags,f))
11452 {
11453 new_return(91);
11454 }
11455 //somehow forgot these in the older builds -Z
11456
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[12],f))
11457 {
11458 new_return(92);
11459 }
11460
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[13],f))
11461 {
11462 new_return(93);
11463 }
11464
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].attributes[14],f))
11465 {
11466 new_return(94);
11467 }
11468
11469 //Enemy Editor InitD[] labels
11470
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 9216 times.
82944 for ( int32_t q = 0; q < 8; q++ )
11471 {
11472
2/2
✓ Branch 0 taken 73728 times.
✓ Branch 1 taken 4792320 times.
4866048 for ( int32_t w = 0; w < 65; w++ )
11473 {
11474
1/2
✓ Branch 0 taken 4792320 times.
✗ Branch 1 not taken.
4792320 if(!p_putc(guysbuf[i].initD_label[q][w],f))
11475 {
11476 new_return(95);
11477 }
11478 4792320 }
11479 73728 }
11480
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputl(guysbuf[i].moveflags,f))
11481 new_return(99);
11482
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_shadow,f))
11483 new_return(100);
11484
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_death,f))
11485 new_return(101);
11486
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_putc(guysbuf[i].spr_spawn,f))
11487 new_return(102);
11488
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if (!p_putc(guysbuf[i].specialsfx, f))
11489 new_return(103);
11490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9216 times.
9216 if(auto ret = write_weap_data(guysbuf[i].weap_data, f))
11491 return ret;
11492 9216 }
11493
11494
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
11495 {
11496 9 section_size=writesize;
11497 9 }
11498 18 }
11499
11500
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
11501 {
11502 char ebuf[80];
11503 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
11504 jwin_alert("Error: writeguys()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
11505 }
11506
11507 9 new_return(0);
11508 9 }
11509
11510 9 int32_t writeherosprites(PACKFILE *f, zquestheader *Header)
11511 {
11512 //these are here to bypass compiler warnings about unused arguments
11513 9 Header=Header;
11514
11515 9 dword section_id=ID_HEROSPRITES;
11516 9 dword section_version=V_HEROSPRITES;
11517 9 dword section_size=0;
11518
11519 //section id
11520
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
11521 {
11522 new_return(1);
11523 }
11524
11525 //section version info
11526
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
11527 {
11528 new_return(2);
11529 }
11530
11531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
11532 {
11533 new_return(3);
11534 }
11535
11536
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
11537 {
11538 18 fake_pack_writing=(writecycle==0);
11539
11540 //section size
11541
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
11542 {
11543 new_return(4);
11544 }
11545
11546 18 writesize=0;
11547
11548 //finally... section data
11549
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11550 {
11551
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(walkspr[i][spr_tile],f))
11552 {
11553 new_return(5);
11554 }
11555
11556
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_flip],f))
11557 {
11558 new_return(5);
11559 }
11560
11561
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)walkspr[i][spr_extend],f))
11562 {
11563 new_return(5);
11564 }
11565 72 }
11566
11567
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11568 {
11569
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stabspr[i][spr_tile],f))
11570 {
11571 new_return(6);
11572 }
11573
11574
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_flip],f))
11575 {
11576 new_return(6);
11577 }
11578
11579
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stabspr[i][spr_extend],f))
11580 {
11581 new_return(6);
11582 }
11583 72 }
11584
11585
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11586 {
11587
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashspr[i][spr_tile],f))
11588 {
11589 new_return(7);
11590 }
11591
11592
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_flip],f))
11593 {
11594 new_return(7);
11595 }
11596
11597
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashspr[i][spr_extend],f))
11598 {
11599 new_return(7);
11600 }
11601 72 }
11602
11603
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11604 {
11605
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(floatspr[i][spr_tile],f))
11606 {
11607 new_return(8);
11608 }
11609
11610
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_flip],f))
11611 {
11612 new_return(8);
11613 }
11614
11615
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)floatspr[i][spr_extend],f))
11616 {
11617 new_return(8);
11618 }
11619 72 }
11620
11621
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11622 {
11623
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(swimspr[i][spr_tile],f))
11624 {
11625 new_return(8);
11626 }
11627
11628
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_flip],f))
11629 {
11630 new_return(8);
11631 }
11632
11633
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)swimspr[i][spr_extend],f))
11634 {
11635 new_return(8);
11636 }
11637 72 }
11638
11639
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11640 {
11641
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(divespr[i][spr_tile],f))
11642 {
11643 new_return(9);
11644 }
11645
11646
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_flip],f))
11647 {
11648 new_return(9);
11649 }
11650
11651
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)divespr[i][spr_extend],f))
11652 {
11653 new_return(9);
11654 }
11655 72 }
11656
11657
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11658 {
11659
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(poundspr[i][spr_tile],f))
11660 {
11661 new_return(10);
11662 }
11663
11664
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_flip],f))
11665 {
11666 new_return(10);
11667 }
11668
11669
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)poundspr[i][spr_extend],f))
11670 {
11671 new_return(10);
11672 }
11673 72 }
11674
11675
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(castingspr[spr_tile],f))
11676 {
11677 new_return(11);
11678 }
11679
11680
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_flip],f))
11681 {
11682 new_return(11);
11683 }
11684
11685
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)castingspr[spr_extend],f))
11686 {
11687 new_return(11);
11688 }
11689
11690
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for(int32_t i=0; i<2; i++)
11691 {
11692
2/2
✓ Branch 0 taken 108 times.
✓ Branch 1 taken 36 times.
144 for(int32_t j=0; j<spr_holdmax; j++)
11693 {
11694
1/2
✓ Branch 0 taken 108 times.
✗ Branch 1 not taken.
108 if(!p_iputl(holdspr[i][j][spr_tile],f))
11695 {
11696 new_return(12);
11697 }
11698
11699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_flip],f))
11700 {
11701 new_return(12);
11702 }
11703
11704
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 108 times.
108 if(!p_putc((byte)holdspr[i][j][spr_extend],f))
11705 {
11706 new_return(12);
11707 }
11708 108 }
11709 36 }
11710
11711
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11712 {
11713
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(jumpspr[i][spr_tile],f))
11714 {
11715 new_return(13);
11716 }
11717
11718
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_flip],f))
11719 {
11720 new_return(13);
11721 }
11722
11723
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)jumpspr[i][spr_extend],f))
11724 {
11725 new_return(13);
11726 }
11727 72 }
11728
11729
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
11730 {
11731
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(chargespr[i][spr_tile],f))
11732 {
11733 new_return(13);
11734 }
11735
11736
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_flip],f))
11737 {
11738 new_return(13);
11739 }
11740
11741
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)chargespr[i][spr_extend],f))
11742 {
11743 new_return(13);
11744 }
11745 72 }
11746
11747
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)zinit.hero_swim_speed,f))
11748 {
11749 new_return(14);
11750 }
11751
11752 //{ V_HEROSPRITES >= 7
11753
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11754 {
11755
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozenspr[q][spr_tile],f))
11756 new_return(15);
11757
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_flip],f))
11758 new_return(15);
11759
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozenspr[q][spr_extend],f))
11760 new_return(15);
11761 72 }
11762
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11763 {
11764
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(frozen_waterspr[q][spr_tile],f))
11765 new_return(15);
11766
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_flip],f))
11767 new_return(15);
11768
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)frozen_waterspr[q][spr_extend],f))
11769 new_return(15);
11770 72 }
11771
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11772 {
11773
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfirespr[q][spr_tile],f))
11774 new_return(15);
11775
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_flip],f))
11776 new_return(15);
11777
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfirespr[q][spr_extend],f))
11778 new_return(15);
11779 72 }
11780
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11781 {
11782
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(onfire_waterspr[q][spr_tile],f))
11783 new_return(15);
11784
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_flip],f))
11785 new_return(15);
11786
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)onfire_waterspr[q][spr_extend],f))
11787 new_return(15);
11788 72 }
11789
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11790 {
11791
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(diggingspr[q][spr_tile],f))
11792 new_return(15);
11793
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_flip],f))
11794 new_return(15);
11795
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)diggingspr[q][spr_extend],f))
11796 new_return(15);
11797 72 }
11798
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11799 {
11800
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingrodspr[q][spr_tile],f))
11801 new_return(15);
11802
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_flip],f))
11803 new_return(15);
11804
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingrodspr[q][spr_extend],f))
11805 new_return(15);
11806 72 }
11807
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11808 {
11809
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(usingcanespr[q][spr_tile],f))
11810 new_return(15);
11811
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_flip],f))
11812 new_return(15);
11813
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)usingcanespr[q][spr_extend],f))
11814 new_return(15);
11815 72 }
11816
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11817 {
11818
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pushingspr[q][spr_tile],f))
11819 new_return(15);
11820
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_flip],f))
11821 new_return(15);
11822
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pushingspr[q][spr_extend],f))
11823 new_return(15);
11824 72 }
11825
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11826 {
11827
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingspr[q][spr_tile],f))
11828 new_return(15);
11829
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_flip],f))
11830 new_return(15);
11831
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_extend],f))
11832 new_return(15);
11833
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingspr[q][spr_frames],f))
11834 new_return(15);
11835 72 }
11836
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11837 {
11838
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(liftingwalkspr[q][spr_tile],f))
11839 new_return(15);
11840
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_flip],f))
11841 new_return(15);
11842
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)liftingwalkspr[q][spr_extend],f))
11843 new_return(15);
11844 72 }
11845
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11846 {
11847
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunnedspr[q][spr_tile],f))
11848 new_return(15);
11849
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_flip],f))
11850 new_return(15);
11851
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunnedspr[q][spr_extend],f))
11852 new_return(15);
11853 72 }
11854
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11855 {
11856
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(stunned_waterspr[q][spr_tile],f))
11857 new_return(15);
11858
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_flip],f))
11859 new_return(15);
11860
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)stunned_waterspr[q][spr_extend],f))
11861 new_return(15);
11862 72 }
11863
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11864 {
11865
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowningspr[q][spr_tile],f))
11866 new_return(15);
11867
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_flip],f))
11868 new_return(15);
11869
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowningspr[q][spr_extend],f))
11870 new_return(15);
11871 72 }
11872
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11873 {
11874
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(drowning_lavaspr[q][spr_tile],f))
11875 new_return(15);
11876
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_flip],f))
11877 new_return(15);
11878
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)drowning_lavaspr[q][spr_extend],f))
11879 new_return(15);
11880 72 }
11881
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11882 {
11883
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(fallingspr[q][spr_tile],f))
11884 new_return(15);
11885
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_flip],f))
11886 new_return(15);
11887
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)fallingspr[q][spr_extend],f))
11888 new_return(15);
11889 72 }
11890
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11891 {
11892
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shockedspr[q][spr_tile],f))
11893 new_return(15);
11894
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_flip],f))
11895 new_return(15);
11896
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shockedspr[q][spr_extend],f))
11897 new_return(15);
11898 72 }
11899
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11900 {
11901
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(shocked_waterspr[q][spr_tile],f))
11902 new_return(15);
11903
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_flip],f))
11904 new_return(15);
11905
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)shocked_waterspr[q][spr_extend],f))
11906 new_return(15);
11907 72 }
11908
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11909 {
11910
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(pullswordspr[q][spr_tile],f))
11911 new_return(15);
11912
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_flip],f))
11913 new_return(15);
11914
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)pullswordspr[q][spr_extend],f))
11915 new_return(15);
11916 72 }
11917
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11918 {
11919
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(readingspr[q][spr_tile],f))
11920 new_return(15);
11921
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_flip],f))
11922 new_return(15);
11923
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)readingspr[q][spr_extend],f))
11924 new_return(15);
11925 72 }
11926
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11927 {
11928
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slash180spr[q][spr_tile],f))
11929 new_return(15);
11930
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_flip],f))
11931 new_return(15);
11932
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slash180spr[q][spr_extend],f))
11933 new_return(15);
11934 72 }
11935
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11936 {
11937
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(slashZ4spr[q][spr_tile],f))
11938 new_return(15);
11939
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_flip],f))
11940 new_return(15);
11941
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)slashZ4spr[q][spr_extend],f))
11942 new_return(15);
11943 72 }
11944
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11945 {
11946
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(dashspr[q][spr_tile],f))
11947 new_return(15);
11948
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_flip],f))
11949 new_return(15);
11950
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)dashspr[q][spr_extend],f))
11951 new_return(15);
11952 72 }
11953
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11954 {
11955
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(bonkspr[q][spr_tile],f))
11956 new_return(15);
11957
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_flip],f))
11958 new_return(15);
11959
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)bonkspr[q][spr_extend],f))
11960 new_return(15);
11961 72 }
11962
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q) //Not directions; number of medallion sprs
11963 {
11964
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(medallionsprs[q][spr_tile],f))
11965 new_return(15);
11966
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_flip],f))
11967 new_return(15);
11968
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)medallionsprs[q][spr_extend],f))
11969 new_return(15);
11970 54 }
11971
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11972 {
11973
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimspr[q][spr_tile],f))
11974 new_return(16);
11975
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_flip],f))
11976 new_return(16);
11977
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimspr[q][spr_extend],f))
11978 new_return(16);
11979 72 }
11980
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11981 {
11982
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimslashspr[q][spr_tile],f))
11983 new_return(17);
11984
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_flip],f))
11985 new_return(17);
11986
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimslashspr[q][spr_extend],f))
11987 new_return(17);
11988 72 }
11989
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11990 {
11991
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimstabspr[q][spr_tile],f))
11992 new_return(17);
11993
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_flip],f))
11994 new_return(17);
11995
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimstabspr[q][spr_extend],f))
11996 new_return(17);
11997 72 }
11998
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
11999 {
12000
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimpoundspr[q][spr_tile],f))
12001 new_return(17);
12002
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_flip],f))
12003 new_return(17);
12004
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimpoundspr[q][spr_extend],f))
12005 new_return(17);
12006 72 }
12007
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12008 {
12009
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sideswimchargespr[q][spr_tile],f))
12010 new_return(18);
12011
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_flip],f))
12012 new_return(18);
12013
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sideswimchargespr[q][spr_extend],f))
12014 new_return(18);
12015 72 }
12016
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12017 {
12018
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(hammeroffsets[q],f))
12019 new_return(19);
12020 72 }
12021
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for(int32_t q = 0; q < 3; ++q)
12022 {
12023
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_iputl(sideswimholdspr[q][spr_tile],f))
12024 new_return(20);
12025
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_flip],f))
12026 new_return(20);
12027
1/2
✓ Branch 0 taken 54 times.
✗ Branch 1 not taken.
54 if(!p_putc((byte)sideswimholdspr[q][spr_extend],f))
12028 new_return(20);
12029 54 }
12030
12031
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(sideswimcastingspr[spr_tile],f))
12032 {
12033 new_return(21);
12034 }
12035
12036
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_flip],f))
12037 {
12038 new_return(21);
12039 }
12040
12041
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc((byte)sideswimcastingspr[spr_extend],f))
12042 {
12043 new_return(21);
12044 }
12045
12046
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t q = 0; q < 4; ++q)
12047 {
12048
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(sidedrowningspr[q][spr_tile],f))
12049 new_return(22);
12050
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_flip],f))
12051 new_return(22);
12052
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)sidedrowningspr[q][spr_extend],f))
12053 new_return(22);
12054 72 }
12055
12056
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int32_t i=0; i<4; i++)
12057 {
12058
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(revslashspr[i][spr_tile],f))
12059 {
12060 new_return(23);
12061 }
12062
12063
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_flip],f))
12064 {
12065 new_return(23);
12066 }
12067
12068
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_putc((byte)revslashspr[i][spr_extend],f))
12069 {
12070 new_return(23);
12071 }
12072 72 }
12073
12074
12075
2/2
✓ Branch 0 taken 2628 times.
✓ Branch 1 taken 18 times.
2646 for (int32_t q = 0; q < wMax; q++) // Hero defense values
12076 {
12077
1/2
✓ Branch 0 taken 2628 times.
✗ Branch 1 not taken.
2628 if (!p_putc(hero_defenses[q], f))
12078 new_return(15);
12079 2628 }
12080 //}
12081
12082
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12083 {
12084 9 section_size=writesize;
12085 9 }
12086 18 }
12087
12088 //More data will come here
12089
12090
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12091 {
12092 char ebuf[80];
12093 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12094 jwin_alert("Error: writeherosprites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12095 }
12096
12097 9 new_return(0);
12098 }
12099
12100 9 int32_t writesubscreens(PACKFILE *f, zquestheader *Header)
12101 {
12102 9 dword section_id=ID_SUBSCREEN;
12103 9 dword section_version=V_SUBSCREEN;
12104 9 dword section_size=0;
12105
12106 //section id
12107
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
12108 {
12109 new_return(1);
12110 }
12111
12112 //section version info
12113
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
12114 {
12115 new_return(2);
12116 }
12117
12118
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!write_deprecated_section_cversion(section_version,f))
12119 {
12120 new_return(3);
12121 }
12122
12123
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12124 {
12125 18 fake_pack_writing=(writecycle==0);
12126
12127 //section size
12128
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
12129 {
12130 new_return(4);
12131 }
12132
12133 18 writesize=0;
12134
12135 18 byte sz = subscreens_active.size();
12136
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12137 new_return(5);
12138
2/2
✓ Branch 0 taken 86 times.
✓ Branch 1 taken 18 times.
104 for(int32_t i=0; i<sz; i++)
12139 {
12140 86 int32_t ret = subscreens_active[i].write(f);
12141 86 fake_pack_writing=(writecycle==0);
12142
12143
1/2
✓ Branch 0 taken 86 times.
✗ Branch 1 not taken.
86 if(ret!=0)
12144 new_return(ret);
12145 86 }
12146
12147 18 sz = subscreens_passive.size();
12148
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12149 new_return(5);
12150
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 18 times.
82 for(int32_t i=0; i<sz; i++)
12151 {
12152 64 int32_t ret = subscreens_passive[i].write(f);
12153 64 fake_pack_writing=(writecycle==0);
12154
12155
1/2
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
64 if(ret!=0)
12156 new_return(ret);
12157 64 }
12158
12159 18 sz = subscreens_overlay.size();
12160
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(sz,f))
12161 new_return(5);
12162
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 for(int32_t i=0; i<sz; i++)
12163 {
12164 int32_t ret = subscreens_overlay[i].write(f);
12165 fake_pack_writing=(writecycle==0);
12166
12167 if(ret!=0)
12168 new_return(ret);
12169 }
12170
12171
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
12172 {
12173 9 section_size=writesize;
12174 9 }
12175 18 }
12176
12177
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
12178 {
12179 char ebuf[80];
12180 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12181 jwin_alert("Error: writesubscreens()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12182 }
12183
12184 9 new_return(0);
12185 9 }
12186
12187 extern script_data *ffscripts[NUMSCRIPTFFC];
12188 extern script_data *itemscripts[NUMSCRIPTITEM];
12189 extern script_data *guyscripts[NUMSCRIPTGUYS];
12190 extern script_data *lwpnscripts[NUMSCRIPTWEAPONS];
12191 extern script_data *ewpnscripts[NUMSCRIPTWEAPONS];
12192 extern script_data *globalscripts[NUMSCRIPTGLOBAL];
12193 extern script_data *genericscripts[NUMSCRIPTSGENERIC];
12194 extern script_data *playerscripts[NUMSCRIPTHERO];
12195 extern script_data *screenscripts[NUMSCRIPTSCREEN];
12196 extern script_data *dmapscripts[NUMSCRIPTSDMAP];
12197 extern script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
12198 extern script_data *comboscripts[NUMSCRIPTSCOMBODATA];
12199 extern script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
12200
12201 9 int32_t writeffscript(PACKFILE *f, zquestheader *Header)
12202 {
12203
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
9 if (QMisc.zscript_last_compiled_version <= 26)
12204 3 return writeffscript_old(f, Header);
12205
12206 6 dword section_id = ID_FFSCRIPT;
12207 6 dword section_version = V_FFSCRIPT;
12208 6 dword section_size = 0;
12209 6 dword zasmmeta_version = METADATA_V;
12210 6 byte numscripts = 0;
12211 6 numscripts = numscripts; //to avoid unused variables warnings
12212
12213 //section id
12214
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_mputl(section_id,f))
12215 {
12216 new_return(1);
12217 }
12218
12219 //section version info
12220
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(section_version,f))
12221 {
12222 new_return(2);
12223 }
12224
12225
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!write_deprecated_section_cversion(section_version,f))
12226 {
12227 new_return(3);
12228 }
12229
12230
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputw(zasmmeta_version,f))
12231 {
12232 new_return(4);
12233 }
12234
12235
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t writecycle=0; writecycle<2; ++writecycle)
12236 {
12237 12 fake_pack_writing=(writecycle==0);
12238
12239 //section size
12240
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(section_size,f))
12241 {
12242 new_return(5);
12243 }
12244
12245 12 writesize=0;
12246
12247 12 write_quest_zasm(f);
12248
12249
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
12250 {
12251 6144 int32_t ret = write_one_ffscript(f, Header, i, ffscripts[i]);
12252
12253
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12254 {
12255 new_return(ret);
12256 }
12257 6144 }
12258
12259
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
12260 {
12261 3072 int32_t ret = write_one_ffscript(f, Header, i, itemscripts[i]);
12262
12263
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12264 {
12265 new_return(ret);
12266 }
12267 3072 }
12268
12269
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
12270 {
12271 3072 int32_t ret = write_one_ffscript(f, Header, i, guyscripts[i]);
12272
12273
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12274 {
12275 new_return(ret);
12276 }
12277 3072 }
12278
12279
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 script_data *fake = new script_data(ScriptType::None, 0);
12280
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12281 {
12282 3072 int32_t ret = write_one_ffscript(f, Header, i, fake);
12283
12284
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12285 {
12286 new_return(ret);
12287 }
12288 3072 }
12289
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 delete fake;
12290
12291
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
12292 {
12293 3072 int32_t ret = write_one_ffscript(f, Header, i, screenscripts[i]);
12294
12295
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12296 {
12297 new_return(ret);
12298 }
12299 3072 }
12300
12301
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
12302 {
12303 96 int32_t ret = write_one_ffscript(f, Header, i, globalscripts[i]);
12304
12305
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(ret!=0)
12306 {
12307 new_return(ret);
12308 }
12309 96 }
12310
12311
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
12312 {
12313 60 int32_t ret = write_one_ffscript(f, Header, i, playerscripts[i]);
12314
12315
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 if(ret!=0)
12316 {
12317 new_return(ret);
12318 }
12319 60 }
12320
12321
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12322 {
12323 3072 int32_t ret = write_one_ffscript(f, Header, i, lwpnscripts[i]);
12324
12325
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12326 {
12327 new_return(ret);
12328 }
12329 3072 }
12330
12331
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
12332 {
12333 3072 int32_t ret = write_one_ffscript(f, Header, i, ewpnscripts[i]);
12334
12335
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12336 {
12337 new_return(ret);
12338 }
12339 3072 }
12340
12341
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
12342 {
12343 3072 int32_t ret = write_one_ffscript(f, Header, i, dmapscripts[i]);
12344
12345
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12346 {
12347 new_return(ret);
12348 }
12349 3072 }
12350
12351
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
12352 {
12353 3072 int32_t ret = write_one_ffscript(f, Header, i, itemspritescripts[i]);
12354
12355
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12356 {
12357 new_return(ret);
12358 }
12359 3072 }
12360
12361
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
12362 {
12363 6144 int32_t ret = write_one_ffscript(f, Header, i, comboscripts[i]);
12364
12365
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12366 {
12367 new_return(ret);
12368 }
12369 6144 }
12370
12371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSGENERIC,f))
12372 {
12373 new_return(2000);
12374 }
12375
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
12376 {
12377 6144 int32_t ret = write_one_ffscript(f, Header, i, genericscripts[i]);
12378
12379
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 if(ret!=0)
12380 {
12381 new_return(ret);
12382 }
12383 6144 }
12384
12385
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
12386 {
12387 new_return(2001);
12388 }
12389
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
12390 {
12391 3072 int32_t ret = write_one_ffscript(f, Header, i, subscreenscripts[i]);
12392
12393
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
12394 {
12395 new_return(ret);
12396 }
12397 3072 }
12398
12399
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputl((int32_t)zScript.size(), f))
12400 {
12401 new_return(2001);
12402 }
12403
12404
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
12405 {
12406 new_return(2002);
12407 }
12408
12409 12 word numffcbindings=0;
12410
12411
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12412 {
12413
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12414 {
12415 158 numffcbindings++;
12416 158 }
12417 6132 }
12418
12419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numffcbindings, f))
12420 {
12421 new_return(2003);
12422 }
12423
12424
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
12425 {
12426
2/2
✓ Branch 0 taken 5974 times.
✓ Branch 1 taken 158 times.
6132 if(it->second.scriptname != "")
12427 {
12428
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputw(it->first,f))
12429 {
12430 new_return(2004);
12431 }
12432
12433
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12434 {
12435 new_return(2005);
12436 }
12437
12438
1/2
✓ Branch 0 taken 158 times.
✗ Branch 1 not taken.
158 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12439 {
12440 new_return(2006);
12441 }
12442 158 }
12443 6132 }
12444
12445 12 word numglobalbindings=0;
12446
12447
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12448 {
12449
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12450 {
12451 22 numglobalbindings++;
12452 22 }
12453 96 }
12454
12455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numglobalbindings, f))
12456 {
12457 new_return(2007);
12458 }
12459
12460
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
12461 {
12462
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 22 times.
96 if(it->second.scriptname != "")
12463 {
12464
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputw(it->first,f))
12465 {
12466 new_return(2008);
12467 }
12468
12469
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12470 {
12471 new_return(2009);
12472 }
12473
12474
1/2
✓ Branch 0 taken 22 times.
✗ Branch 1 not taken.
22 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12475 {
12476 new_return(2010);
12477 }
12478 22 }
12479 96 }
12480
12481 12 word numitembindings=0;
12482
12483
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12484 {
12485
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12486 {
12487 26 numitembindings++;
12488 26 }
12489 3060 }
12490
12491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitembindings, f))
12492 {
12493 new_return(2011);
12494 }
12495
12496
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
12497 {
12498
2/2
✓ Branch 0 taken 3034 times.
✓ Branch 1 taken 26 times.
3060 if(it->second.scriptname != "")
12499 {
12500
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputw(it->first,f))
12501 {
12502 new_return(2012);
12503 }
12504
12505
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12506 {
12507 new_return(2013);
12508 }
12509
12510
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12511 {
12512 new_return(2014);
12513 }
12514 26 }
12515 3060 }
12516
12517 //new script types
12518 //npc scripts
12519 12 word numnpcbindings=0;
12520
12521
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12522 {
12523
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12524 {
12525 numnpcbindings++;
12526 }
12527 3060 }
12528
12529
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numnpcbindings, f))
12530 {
12531 new_return(2015);
12532 }
12533
12534
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
12535 {
12536
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12537 {
12538 if(!p_iputw(it->first,f))
12539 {
12540 new_return(2016);
12541 }
12542
12543 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12544 {
12545 new_return(2017);
12546 }
12547
12548 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12549 {
12550 new_return(2018);
12551 }
12552 }
12553 3060 }
12554
12555 //lweapon
12556
12557 12 word numlwpnbindings=0;
12558
12559
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12560 {
12561
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12562 {
12563 2 numlwpnbindings++;
12564 2 }
12565 3060 }
12566
12567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numlwpnbindings, f))
12568 {
12569 new_return(2019);
12570 }
12571
12572
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
12573 {
12574
2/2
✓ Branch 0 taken 3058 times.
✓ Branch 1 taken 2 times.
3060 if(it->second.scriptname != "")
12575 {
12576
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
12577 {
12578 new_return(2020);
12579 }
12580
12581
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12582 {
12583 new_return(2021);
12584 }
12585
12586
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12587 {
12588 new_return(2022);
12589 }
12590 2 }
12591 3060 }
12592
12593 //////
12594
12595 //eweapon
12596
12597
12598 12 word numewpnbindings=0;
12599
12600
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12601 {
12602
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12603 {
12604 numewpnbindings++;
12605 }
12606 3060 }
12607
12608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numewpnbindings, f))
12609 {
12610 new_return(2023);
12611 }
12612
12613
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
12614 {
12615
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12616 {
12617 if(!p_iputw(it->first,f))
12618 {
12619 new_return(2024);
12620 }
12621
12622 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12623 {
12624 new_return(2025);
12625 }
12626
12627 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12628 {
12629 new_return(2026);
12630 }
12631 }
12632 3060 }
12633
12634 //player scripts
12635 12 word numherobindings=0;
12636
12637
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12638 {
12639
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12640 {
12641 numherobindings++;
12642 }
12643 48 }
12644
12645
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numherobindings, f))
12646 {
12647 new_return(2027);
12648 }
12649
12650
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
12651 {
12652
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(it->second.scriptname != "")
12653 {
12654 if(!p_iputw(it->first,f))
12655 {
12656 new_return(2028);
12657 }
12658
12659 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12660 {
12661 new_return(2029);
12662 }
12663
12664 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12665 {
12666 new_return(2030);
12667 }
12668 }
12669 48 }
12670
12671 //dmap scripts
12672 12 word numdmapbindings=0;
12673
12674
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12675 {
12676
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12677 {
12678 10 numdmapbindings++;
12679 10 }
12680 3060 }
12681
12682
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numdmapbindings, f))
12683 {
12684 new_return(2031);
12685 }
12686
12687
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
12688 {
12689
2/2
✓ Branch 0 taken 3050 times.
✓ Branch 1 taken 10 times.
3060 if(it->second.scriptname != "")
12690 {
12691
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputw(it->first,f))
12692 {
12693 new_return(2032);
12694 }
12695
12696
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12697 {
12698 new_return(2033);
12699 }
12700
12701
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12702 {
12703 new_return(2034);
12704 }
12705 10 }
12706 3060 }
12707
12708 //screen scripts
12709 12 word numscreenbindings=0;
12710
12711
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12712 {
12713
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12714 {
12715 4 numscreenbindings++;
12716 4 }
12717 3060 }
12718
12719
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numscreenbindings, f))
12720 {
12721 new_return(2035);
12722 }
12723
12724
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
12725 {
12726
2/2
✓ Branch 0 taken 3056 times.
✓ Branch 1 taken 4 times.
3060 if(it->second.scriptname != "")
12727 {
12728
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputw(it->first,f))
12729 {
12730 new_return(2036);
12731 }
12732
12733
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12734 {
12735 new_return(2037);
12736 }
12737
12738
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12739 {
12740 new_return(2038);
12741 }
12742 4 }
12743 3060 }
12744 //item sprite scripts
12745 12 word numitemspritebindings=0;
12746
12747
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12748 {
12749
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12750 {
12751 numitemspritebindings++;
12752 }
12753 3060 }
12754
12755
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numitemspritebindings, f))
12756 {
12757 new_return(2039);
12758 }
12759
12760
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
12761 {
12762
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12763 {
12764 if(!p_iputw(it->first,f))
12765 {
12766 new_return(2040);
12767 }
12768
12769 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12770 {
12771 new_return(2041);
12772 }
12773
12774 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12775 {
12776 new_return(2042);
12777 }
12778 }
12779 3060 }
12780
12781 //combo scripts
12782 12 word numcombobindings=0;
12783
12784
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12785 {
12786
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12787 {
12788 numcombobindings++;
12789 }
12790 6132 }
12791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numcombobindings, f))
12792 {
12793 new_return(2043);
12794 }
12795
12796
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
12797 {
12798
1/2
✓ Branch 0 taken 6132 times.
✗ Branch 1 not taken.
6132 if(it->second.scriptname != "")
12799 {
12800 if(!p_iputw(it->first,f))
12801 {
12802 new_return(2044);
12803 }
12804
12805 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12806 {
12807 new_return(2045);
12808 }
12809
12810 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12811 {
12812 new_return(2046);
12813 }
12814 }
12815 6132 }
12816 //subscreen scripts
12817 12 word numgenericbindings=0;
12818
12819
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12820 {
12821
2/2
✓ Branch 0 taken 6090 times.
✓ Branch 1 taken 42 times.
6132 if(it->second.scriptname != "")
12822 {
12823 42 numgenericbindings++;
12824 42 }
12825 6132 }
12826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numgenericbindings, f))
12827 {
12828 new_return(2043);
12829 }
12830
12831
2/2
✓ Branch 0 taken 6132 times.
✓ Branch 1 taken 12 times.
6144 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
12832 {
12833
2/2
✓ Branch 0 taken 6090 times.
✓ Branch 1 taken 42 times.
6132 if(it->second.scriptname != "")
12834 {
12835
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!p_iputw(it->first,f))
12836 {
12837 new_return(2044);
12838 }
12839
12840
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12841 {
12842 new_return(2045);
12843 }
12844
12845
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12846 {
12847 new_return(2046);
12848 }
12849 42 }
12850 6132 }
12851
12852 //generic scripts
12853 12 word numsubscreenbindings=0;
12854
12855
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12856 {
12857
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12858 {
12859 numsubscreenbindings++;
12860 }
12861 3060 }
12862
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!p_iputw(numsubscreenbindings, f))
12863 {
12864 new_return(2047);
12865 }
12866
12867
2/2
✓ Branch 0 taken 3060 times.
✓ Branch 1 taken 12 times.
3072 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
12868 {
12869
1/2
✓ Branch 0 taken 3060 times.
✗ Branch 1 not taken.
3060 if(it->second.scriptname != "")
12870 {
12871 if(!p_iputw(it->first,f))
12872 {
12873 new_return(2048);
12874 }
12875
12876 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
12877 {
12878 new_return(2049);
12879 }
12880
12881 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
12882 {
12883 new_return(2050);
12884 }
12885 }
12886 3060 }
12887
12888
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if(writecycle==0)
12889 {
12890 6 section_size=writesize;
12891 6 }
12892 12 }
12893
12894
12895
12896
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if(writesize!=int32_t(section_size) && save_warn)
12897 {
12898 char ebuf[80];
12899 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
12900 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
12901 }
12902
12903 6 new_return(0);
12904 //return 0; //this is just here to stomp the compiler from whining.
12905 //the irony is that it causes an "unreachable code" warning.
12906 9 }
12907
12908 12 int32_t write_quest_zasm(PACKFILE *f)
12909 {
12910 extern std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
12911
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (zasm_scripts.empty())
12912 {
12913 if(!p_iputl(0,f))
12914 new_return(1);
12915
12916 return 0;
12917 }
12918
12919 12 auto& zasm = zasm_scripts[0]->zasm;
12920 12 size_t num_commands = zasm.size();
12921
12922
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!p_iputl(num_commands,f))
12923 new_return(1);
12924
12925
2/2
✓ Branch 0 taken 372806 times.
✓ Branch 1 taken 12 times.
372818 for(int32_t j=0; j<num_commands; j++)
12926 {
12927 372806 auto& zas = zasm[j];
12928
12929
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 372806 times.
372806 if(zas.command==0xFFFF)
12930 continue;
12931 else
12932 {
12933
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputw(zas.command,f))
12934 new_return(2);
12935
12936
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg1,f))
12937 new_return(3);
12938
12939
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg2,f))
12940 new_return(4);
12941
12942
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(zas.arg3,f))
12943 new_return(5);
12944
12945 372806 uint32_t sz = 0;
12946
2/2
✓ Branch 0 taken 371822 times.
✓ Branch 1 taken 984 times.
372806 if(zas.strptr)
12947 984 sz = zas.strptr->size();
12948
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(sz,f))
12949 new_return(6);
12950
2/2
✓ Branch 0 taken 371834 times.
✓ Branch 1 taken 972 times.
372806 if(sz)
12951 {
12952 972 auto& str = *zas.strptr;
12953
2/2
✓ Branch 0 taken 20822 times.
✓ Branch 1 taken 972 times.
21794 for(size_t q = 0; q < sz; ++q)
12954 {
12955
1/2
✓ Branch 0 taken 20822 times.
✗ Branch 1 not taken.
20822 if(!p_putc(str[q],f))
12956 new_return(7);
12957 20822 }
12958 972 }
12959 372806 sz = 0;
12960
2/2
✓ Branch 0 taken 372598 times.
✓ Branch 1 taken 208 times.
372806 if(zas.vecptr)
12961 208 sz = zas.vecptr->size();
12962
1/2
✓ Branch 0 taken 372806 times.
✗ Branch 1 not taken.
372806 if(!p_iputl(sz,f))
12963 new_return(8);
12964
2/2
✓ Branch 0 taken 372598 times.
✓ Branch 1 taken 208 times.
372806 if(sz) //vector found
12965 {
12966 208 auto& vec = *zas.vecptr;
12967
2/2
✓ Branch 0 taken 1302 times.
✓ Branch 1 taken 208 times.
1510 for(size_t q = 0; q < sz; ++q)
12968 {
12969
1/2
✓ Branch 0 taken 1302 times.
✗ Branch 1 not taken.
1302 if(!p_iputl(vec[q],f))
12970 new_return(9);
12971 1302 }
12972 208 }
12973 }
12974 372806 }
12975 12 return 0;
12976 12 }
12977
12978 46236 int32_t write_one_ffscript(PACKFILE *f, zquestheader *, int32_t, script_data *script)
12979 {
12980
2/2
✓ Branch 0 taken 45986 times.
✓ Branch 1 taken 250 times.
46236 if (!script->valid())
12981 {
12982
1/2
✓ Branch 0 taken 45986 times.
✗ Branch 1 not taken.
45986 if (!p_putc(0, f))
12983 new_return(-1);
12984 45986 return 0;
12985 }
12986
12987
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if (!p_putc(1, f))
12988 new_return(-1);
12989
12990 250 zasm_meta const& tmeta = script->meta;
12991
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.zasm_v,f))
12992 new_return(1);
12993
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.meta_v,f))
12994 new_return(2);
12995
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.ffscript_v,f))
12996 new_return(3);
12997
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putc((int)tmeta.script_type,f))
12998 new_return(4);
12999
13000
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(int32_t q = 0; q < 8; ++q)
13001 {
13002
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.run_idens[q],f))
13003 new_return(5);
13004 2000 }
13005
13006
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(int32_t q = 0; q < 8; ++q)
13007
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putc(tmeta.run_types[q],f))
13008 new_return(6);
13009
13010
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putc(tmeta.flags,f))
13011 new_return(7);
13012
13013
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v1,f))
13014 new_return(8);
13015
13016
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v2,f))
13017 new_return(9);
13018
13019
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v3,f))
13020 new_return(10);
13021
13022
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputw(tmeta.compiler_v4,f))
13023 new_return(11);
13024
13025
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putcstr(tmeta.script_name,f))
13026 new_return(12);
13027
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_putcstr(tmeta.author,f))
13028 new_return(13);
13029
2/2
✓ Branch 0 taken 2500 times.
✓ Branch 1 taken 250 times.
2750 for(auto q = 0; q < 10; ++q)
13030 {
13031
1/2
✓ Branch 0 taken 2500 times.
✗ Branch 1 not taken.
2500 if(!p_putcstr(tmeta.attributes[q],f))
13032 new_return(14);
13033
1/2
✓ Branch 0 taken 2500 times.
✗ Branch 1 not taken.
2500 if(!p_putwstr(tmeta.attributes_help[q],f))
13034 new_return(15);
13035 2500 }
13036
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13037 {
13038
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.attribytes[q],f))
13039 new_return(16);
13040
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.attribytes_help[q],f))
13041 new_return(17);
13042 2000 }
13043
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13044 {
13045
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.attrishorts[q],f))
13046 new_return(18);
13047
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13048 new_return(19);
13049 2000 }
13050
2/2
✓ Branch 0 taken 4000 times.
✓ Branch 1 taken 250 times.
4250 for(auto q = 0; q < 16; ++q)
13051 {
13052
1/2
✓ Branch 0 taken 4000 times.
✗ Branch 1 not taken.
4000 if(!p_putcstr(tmeta.usrflags[q],f))
13053 new_return(20);
13054
1/2
✓ Branch 0 taken 4000 times.
✗ Branch 1 not taken.
4000 if(!p_putwstr(tmeta.usrflags_help[q],f))
13055 new_return(21);
13056 4000 }
13057
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13058 {
13059
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putcstr(tmeta.initd[q],f))
13060 new_return(22);
13061
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putwstr(tmeta.initd_help[q],f))
13062 new_return(23);
13063 2000 }
13064
2/2
✓ Branch 0 taken 2000 times.
✓ Branch 1 taken 250 times.
2250 for(auto q = 0; q < 8; ++q)
13065 {
13066
1/2
✓ Branch 0 taken 2000 times.
✗ Branch 1 not taken.
2000 if(!p_putc(tmeta.initd_type[q],f))
13067 new_return(24);
13068 2000 }
13069
13070
1/2
✓ Branch 0 taken 250 times.
✗ Branch 1 not taken.
250 if(!p_iputl(script->pc, f))
13071 new_return(25);
13072
13073
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 250 times.
250 if(!p_iputl(script->end_pc, f))
13074 new_return(26);
13075
13076 250 return 0;
13077 46236 }
13078
13079
13080 3 int32_t writeffscript_old(PACKFILE *f, zquestheader *Header)
13081 {
13082 3 dword section_id = ID_FFSCRIPT;
13083 3 dword section_version = 26;
13084 3 dword section_cversion = 1;
13085 3 dword section_size = 0;
13086 3 dword zasmmeta_version = 5;
13087 3 byte numscripts = 0;
13088 3 numscripts = numscripts; //to avoid unused variables warnings
13089
13090 //section id
13091
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_mputl(section_id,f))
13092 {
13093 new_return(1);
13094 }
13095
13096 //section version info
13097
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_version,f))
13098 {
13099 new_return(2);
13100 }
13101
13102
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(section_cversion,f))
13103 {
13104 new_return(3);
13105 }
13106
13107
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(!p_iputw(zasmmeta_version,f))
13108 {
13109 new_return(4);
13110 }
13111
13112
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
9 for(int32_t writecycle=0; writecycle<2; ++writecycle)
13113 {
13114 6 fake_pack_writing=(writecycle==0);
13115
13116 //section size
13117
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!p_iputl(section_size,f))
13118 {
13119 new_return(5);
13120 }
13121
13122 6 writesize=0;
13123
13124
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
13125 {
13126 3072 int32_t ret = write_one_ffscript_old(f, Header, i, ffscripts[i]);
13127 3072 fake_pack_writing=(writecycle==0);
13128
13129
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13130 {
13131 new_return(ret);
13132 }
13133 3072 }
13134
13135
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
13136 {
13137 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemscripts[i]);
13138 1536 fake_pack_writing=(writecycle==0);
13139
13140
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13141 {
13142 new_return(ret);
13143 }
13144 1536 }
13145
13146
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
13147 {
13148 1536 int32_t ret = write_one_ffscript_old(f, Header, i, guyscripts[i]);
13149 1536 fake_pack_writing=(writecycle==0);
13150
13151
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13152 {
13153 new_return(ret);
13154 }
13155 1536 }
13156
13157
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 script_data *fake = new script_data(ScriptType::None, 0);
13158
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13159 {
13160 1536 int32_t ret = write_one_ffscript_old(f, Header, i, fake);
13161 1536 fake_pack_writing=(writecycle==0);
13162
13163
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13164 {
13165 new_return(ret);
13166 }
13167 1536 }
13168
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 delete fake;
13169
13170
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
13171 {
13172 1536 int32_t ret = write_one_ffscript_old(f, Header, i, screenscripts[i]);
13173 1536 fake_pack_writing=(writecycle==0);
13174
13175
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13176 {
13177 new_return(ret);
13178 }
13179 1536 }
13180
13181
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
13182 {
13183 48 int32_t ret = write_one_ffscript_old(f, Header, i, globalscripts[i]);
13184 48 fake_pack_writing=(writecycle==0);
13185
13186
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(ret!=0)
13187 {
13188 new_return(ret);
13189 }
13190 48 }
13191
13192
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 6 times.
36 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
13193 {
13194 30 int32_t ret = write_one_ffscript_old(f, Header, i, playerscripts[i]);
13195 30 fake_pack_writing=(writecycle==0);
13196
13197
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if(ret!=0)
13198 {
13199 new_return(ret);
13200 }
13201 30 }
13202
13203
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13204 {
13205 1536 int32_t ret = write_one_ffscript_old(f, Header, i, lwpnscripts[i]);
13206 1536 fake_pack_writing=(writecycle==0);
13207
13208
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13209 {
13210 new_return(ret);
13211 }
13212 1536 }
13213
13214
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
13215 {
13216 1536 int32_t ret = write_one_ffscript_old(f, Header, i, ewpnscripts[i]);
13217 1536 fake_pack_writing=(writecycle==0);
13218
13219
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13220 {
13221 new_return(ret);
13222 }
13223 1536 }
13224
13225
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
13226 {
13227 1536 int32_t ret = write_one_ffscript_old(f, Header, i, dmapscripts[i]);
13228 1536 fake_pack_writing=(writecycle==0);
13229
13230
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13231 {
13232 new_return(ret);
13233 }
13234 1536 }
13235
13236
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
13237 {
13238 1536 int32_t ret = write_one_ffscript_old(f, Header, i, itemspritescripts[i]);
13239 1536 fake_pack_writing=(writecycle==0);
13240
13241
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13242 {
13243 new_return(ret);
13244 }
13245 1536 }
13246
13247
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
13248 {
13249 3072 int32_t ret = write_one_ffscript_old(f, Header, i, comboscripts[i]);
13250 3072 fake_pack_writing=(writecycle==0);
13251
13252
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13253 {
13254 new_return(ret);
13255 }
13256 3072 }
13257
13258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSGENERIC,f))
13259 {
13260 new_return(2000);
13261 }
13262
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
13263 {
13264 3072 int32_t ret = write_one_ffscript_old(f, Header, i, genericscripts[i]);
13265 3072 fake_pack_writing=(writecycle==0);
13266
13267
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 if(ret!=0)
13268 {
13269 new_return(ret);
13270 }
13271 3072 }
13272
13273
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(NUMSCRIPTSSUBSCREEN,f))
13274 {
13275 new_return(2001);
13276 }
13277
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
13278 {
13279 1536 int32_t ret = write_one_ffscript_old(f, Header, i, subscreenscripts[i]);
13280 1536 fake_pack_writing=(writecycle==0);
13281
13282
1/2
✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
1536 if(ret!=0)
13283 {
13284 new_return(ret);
13285 }
13286 1536 }
13287
13288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputl((int32_t)zScript.size(), f))
13289 {
13290 new_return(2001);
13291 }
13292
13293
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!pfwrite((void *)zScript.c_str(), (int32_t)zScript.size(), f))
13294 {
13295 new_return(2002);
13296 }
13297
13298 6 word numffcbindings=0;
13299
13300
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13301 {
13302
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13303 {
13304 206 numffcbindings++;
13305 206 }
13306 3066 }
13307
13308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numffcbindings, f))
13309 {
13310 new_return(2003);
13311 }
13312
13313
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = ffcmap.begin(); it != ffcmap.end(); it++)
13314 {
13315
2/2
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 206 times.
3066 if(it->second.scriptname != "")
13316 {
13317
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputw(it->first,f))
13318 {
13319 new_return(2004);
13320 }
13321
13322
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13323 {
13324 new_return(2005);
13325 }
13326
13327
1/2
✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
206 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13328 {
13329 new_return(2006);
13330 }
13331 206 }
13332 3066 }
13333
13334 6 word numglobalbindings=0;
13335
13336
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13337 {
13338
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13339 {
13340 18 numglobalbindings++;
13341 18 }
13342 48 }
13343
13344
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numglobalbindings, f))
13345 {
13346 new_return(2007);
13347 }
13348
13349
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(std::map<int32_t, script_slot_data >::iterator it = globalmap.begin(); it != globalmap.end(); it++)
13350 {
13351
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 18 times.
48 if(it->second.scriptname != "")
13352 {
13353
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13354 {
13355 new_return(2008);
13356 }
13357
13358
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13359 {
13360 new_return(2009);
13361 }
13362
13363
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13364 {
13365 new_return(2010);
13366 }
13367 18 }
13368 48 }
13369
13370 6 word numitembindings=0;
13371
13372
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13373 {
13374
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13375 {
13376 18 numitembindings++;
13377 18 }
13378 1530 }
13379
13380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitembindings, f))
13381 {
13382 new_return(2011);
13383 }
13384
13385
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemmap.begin(); it != itemmap.end(); it++)
13386 {
13387
2/2
✓ Branch 0 taken 1512 times.
✓ Branch 1 taken 18 times.
1530 if(it->second.scriptname != "")
13388 {
13389
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(it->first,f))
13390 {
13391 new_return(2012);
13392 }
13393
13394
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13395 {
13396 new_return(2013);
13397 }
13398
13399
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13400 {
13401 new_return(2014);
13402 }
13403 18 }
13404 1530 }
13405
13406 //new script types
13407 //npc scripts
13408 6 word numnpcbindings=0;
13409
13410
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13411 {
13412
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13413 {
13414 numnpcbindings++;
13415 }
13416 1530 }
13417
13418
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numnpcbindings, f))
13419 {
13420 new_return(2015);
13421 }
13422
13423
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = npcmap.begin(); it != npcmap.end(); it++)
13424 {
13425
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13426 {
13427 if(!p_iputw(it->first,f))
13428 {
13429 new_return(2016);
13430 }
13431
13432 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13433 {
13434 new_return(2017);
13435 }
13436
13437 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13438 {
13439 new_return(2018);
13440 }
13441 }
13442 1530 }
13443
13444 //lweapon
13445
13446 6 word numlwpnbindings=0;
13447
13448
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13449 {
13450
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13451 {
13452 numlwpnbindings++;
13453 }
13454 1530 }
13455
13456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numlwpnbindings, f))
13457 {
13458 new_return(2019);
13459 }
13460
13461
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = lwpnmap.begin(); it != lwpnmap.end(); it++)
13462 {
13463
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13464 {
13465 if(!p_iputw(it->first,f))
13466 {
13467 new_return(2020);
13468 }
13469
13470 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13471 {
13472 new_return(2021);
13473 }
13474
13475 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13476 {
13477 new_return(2022);
13478 }
13479 }
13480 1530 }
13481
13482 //////
13483
13484 //eweapon
13485
13486
13487 6 word numewpnbindings=0;
13488
13489
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13490 {
13491
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13492 {
13493 numewpnbindings++;
13494 }
13495 1530 }
13496
13497
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numewpnbindings, f))
13498 {
13499 new_return(2023);
13500 }
13501
13502
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = ewpnmap.begin(); it != ewpnmap.end(); it++)
13503 {
13504
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13505 {
13506 if(!p_iputw(it->first,f))
13507 {
13508 new_return(2024);
13509 }
13510
13511 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13512 {
13513 new_return(2025);
13514 }
13515
13516 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13517 {
13518 new_return(2026);
13519 }
13520 }
13521 1530 }
13522
13523 //player scripts
13524 6 word numherobindings=0;
13525
13526
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13527 {
13528
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13529 {
13530 2 numherobindings++;
13531 2 }
13532 24 }
13533
13534
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numherobindings, f))
13535 {
13536 new_return(2027);
13537 }
13538
13539
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(std::map<int32_t, script_slot_data >::iterator it = playermap.begin(); it != playermap.end(); it++)
13540 {
13541
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 2 times.
24 if(it->second.scriptname != "")
13542 {
13543
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputw(it->first,f))
13544 {
13545 new_return(2028);
13546 }
13547
13548
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13549 {
13550 new_return(2029);
13551 }
13552
13553
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13554 {
13555 new_return(2030);
13556 }
13557 2 }
13558 24 }
13559
13560 //dmap scripts
13561 6 word numdmapbindings=0;
13562
13563
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13564 {
13565
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13566 {
13567 numdmapbindings++;
13568 }
13569 1530 }
13570
13571
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numdmapbindings, f))
13572 {
13573 new_return(2031);
13574 }
13575
13576
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = dmapmap.begin(); it != dmapmap.end(); it++)
13577 {
13578
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13579 {
13580 if(!p_iputw(it->first,f))
13581 {
13582 new_return(2032);
13583 }
13584
13585 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13586 {
13587 new_return(2033);
13588 }
13589
13590 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13591 {
13592 new_return(2034);
13593 }
13594 }
13595 1530 }
13596
13597 //screen scripts
13598 6 word numscreenbindings=0;
13599
13600
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13601 {
13602
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13603 {
13604 14 numscreenbindings++;
13605 14 }
13606 1530 }
13607
13608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numscreenbindings, f))
13609 {
13610 new_return(2035);
13611 }
13612
13613
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = screenmap.begin(); it != screenmap.end(); it++)
13614 {
13615
2/2
✓ Branch 0 taken 1516 times.
✓ Branch 1 taken 14 times.
1530 if(it->second.scriptname != "")
13616 {
13617
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputw(it->first,f))
13618 {
13619 new_return(2036);
13620 }
13621
13622
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13623 {
13624 new_return(2037);
13625 }
13626
13627
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13628 {
13629 new_return(2038);
13630 }
13631 14 }
13632 1530 }
13633 //item sprite scripts
13634 6 word numitemspritebindings=0;
13635
13636
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13637 {
13638
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13639 {
13640 numitemspritebindings++;
13641 }
13642 1530 }
13643
13644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numitemspritebindings, f))
13645 {
13646 new_return(2039);
13647 }
13648
13649
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(std::map<int32_t, script_slot_data >::iterator it = itemspritemap.begin(); it != itemspritemap.end(); it++)
13650 {
13651
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13652 {
13653 if(!p_iputw(it->first,f))
13654 {
13655 new_return(2040);
13656 }
13657
13658 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13659 {
13660 new_return(2041);
13661 }
13662
13663 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13664 {
13665 new_return(2042);
13666 }
13667 }
13668 1530 }
13669
13670 //combo scripts
13671 6 word numcombobindings=0;
13672
13673
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13674 {
13675
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13676 {
13677 numcombobindings++;
13678 }
13679 3066 }
13680
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numcombobindings, f))
13681 {
13682 new_return(2043);
13683 }
13684
13685
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(std::map<int32_t, script_slot_data >::iterator it = comboscriptmap.begin(); it != comboscriptmap.end(); it++)
13686 {
13687
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13688 {
13689 if(!p_iputw(it->first,f))
13690 {
13691 new_return(2044);
13692 }
13693
13694 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13695 {
13696 new_return(2045);
13697 }
13698
13699 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13700 {
13701 new_return(2046);
13702 }
13703 }
13704 3066 }
13705 //subscreen scripts
13706 6 word numgenericbindings=0;
13707
13708
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13709 {
13710
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13711 {
13712 numgenericbindings++;
13713 }
13714 3066 }
13715
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numgenericbindings, f))
13716 {
13717 new_return(2043);
13718 }
13719
13720
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(auto it = genericmap.begin(); it != genericmap.end(); it++)
13721 {
13722
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(it->second.scriptname != "")
13723 {
13724 if(!p_iputw(it->first,f))
13725 {
13726 new_return(2044);
13727 }
13728
13729 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13730 {
13731 new_return(2045);
13732 }
13733
13734 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13735 {
13736 new_return(2046);
13737 }
13738 }
13739 3066 }
13740
13741 //generic scripts
13742 6 word numsubscreenbindings=0;
13743
13744
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13745 {
13746
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13747 {
13748 numsubscreenbindings++;
13749 }
13750 1530 }
13751
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(!p_iputw(numsubscreenbindings, f))
13752 {
13753 new_return(2047);
13754 }
13755
13756
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(auto it = subscreenmap.begin(); it != subscreenmap.end(); it++)
13757 {
13758
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(it->second.scriptname != "")
13759 {
13760 if(!p_iputw(it->first,f))
13761 {
13762 new_return(2048);
13763 }
13764
13765 if(!p_iputl((int32_t)it->second.scriptname.size(), f))
13766 {
13767 new_return(2049);
13768 }
13769
13770 if(!pfwrite((void *)it->second.scriptname.c_str(), (int32_t)it->second.scriptname.size(),f))
13771 {
13772 new_return(2050);
13773 }
13774 }
13775 1530 }
13776
13777
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(writecycle==0)
13778 {
13779 3 section_size=writesize;
13780 3 }
13781 6 }
13782
13783
13784
13785
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3 if(writesize!=int32_t(section_size) && save_warn)
13786 {
13787 char ebuf[80];
13788 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
13789 jwin_alert("Error: writeffscript()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
13790 }
13791
13792 3 new_return(0);
13793 //return 0; //this is just here to stomp the compiler from whining.
13794 //the irony is that it causes an "unreachable code" warning.
13795 3 }
13796
13797 23118 int32_t write_one_ffscript_old(PACKFILE *f, zquestheader *Header, int32_t i, script_data *script)
13798 {
13799 //these are here to bypass compiler warnings about unused arguments
13800 23118 Header=Header;
13801 23118 i=i;
13802
13803
2/2
✓ Branch 0 taken 11830 times.
✓ Branch 1 taken 11288 times.
23118 size_t num_commands = script->zasm_script ? script->zasm_script->size : 0;
13804
13805
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputl(num_commands,f))
13806 {
13807 new_return(6);
13808 }
13809
13810 //Metadata
13811 23118 zasm_meta const& tmeta = script->meta;
13812
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.zasm_v,f))
13813 {
13814 new_return(7);
13815 }
13816
13817
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.meta_v,f))
13818 {
13819 new_return(8);
13820 }
13821
13822
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.ffscript_v,f))
13823 {
13824 new_return(9);
13825 }
13826
13827
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc((int)tmeta.script_type,f))
13828 {
13829 new_return(10);
13830 }
13831
13832
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13833 {
13834
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.run_idens[q],f))
13835 new_return(11);
13836 184944 }
13837
13838
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(int32_t q = 0; q < 8; ++q)
13839 {
13840
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.run_types[q],f))
13841 {
13842 new_return(12);
13843 }
13844 184944 }
13845
13846
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putc(tmeta.flags,f))
13847 {
13848 new_return(13);
13849 }
13850
13851
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v1,f))
13852 {
13853 new_return(14);
13854 }
13855
13856
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v2,f))
13857 {
13858 new_return(15);
13859 }
13860
13861
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v3,f))
13862 {
13863 new_return(16);
13864 }
13865
13866
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_iputw(tmeta.compiler_v4,f))
13867 {
13868 new_return(17);
13869 }
13870
13871
1/2
✓ Branch 0 taken 23118 times.
✗ Branch 1 not taken.
23118 if(!p_putcstr(tmeta.script_name,f))
13872 new_return(18);
13873
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23118 times.
23118 if(!p_putcstr(tmeta.author,f))
13874 new_return(19);
13875
2/2
✓ Branch 0 taken 231180 times.
✓ Branch 1 taken 23118 times.
254298 for(auto q = 0; q < 10; ++q)
13876 {
13877
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putcstr(tmeta.attributes[q],f))
13878 new_return(27);
13879
1/2
✓ Branch 0 taken 231180 times.
✗ Branch 1 not taken.
231180 if(!p_putwstr(tmeta.attributes_help[q],f))
13880 new_return(28);
13881 231180 }
13882
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13883 {
13884
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attribytes[q],f))
13885 new_return(29);
13886
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attribytes_help[q],f))
13887 new_return(30);
13888 184944 }
13889
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13890 {
13891
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.attrishorts[q],f))
13892 new_return(31);
13893
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.attrishorts_help[q],f))
13894 new_return(32);
13895 184944 }
13896
2/2
✓ Branch 0 taken 369888 times.
✓ Branch 1 taken 23118 times.
393006 for(auto q = 0; q < 16; ++q)
13897 {
13898
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putcstr(tmeta.usrflags[q],f))
13899 new_return(33);
13900
1/2
✓ Branch 0 taken 369888 times.
✗ Branch 1 not taken.
369888 if(!p_putwstr(tmeta.usrflags_help[q],f))
13901 new_return(34);
13902 369888 }
13903
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13904 {
13905
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putcstr(tmeta.initd[q],f))
13906 new_return(35);
13907
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putwstr(tmeta.initd_help[q],f))
13908 new_return(36);
13909 184944 }
13910
2/2
✓ Branch 0 taken 184944 times.
✓ Branch 1 taken 23118 times.
208062 for(auto q = 0; q < 8; ++q)
13911 {
13912
1/2
✓ Branch 0 taken 184944 times.
✗ Branch 1 not taken.
184944 if(!p_putc(tmeta.initd_type[q],f))
13913 new_return(37);
13914 184944 }
13915
13916
2/2
✓ Branch 0 taken 11288 times.
✓ Branch 1 taken 2056888 times.
2068176 for(int32_t j=0; j<num_commands; j++)
13917 {
13918 2056888 auto& zas = script->zasm_script->zasm[j];
13919
1/2
✓ Branch 0 taken 2056888 times.
✗ Branch 1 not taken.
2056888 if(!p_iputw(zas.command,f))
13920 {
13921 new_return(20);
13922 }
13923
13924
2/2
✓ Branch 0 taken 2045058 times.
✓ Branch 1 taken 11830 times.
2056888 if(zas.command==0xFFFF)
13925 {
13926 11830 break;
13927 }
13928 else
13929 {
13930
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg1,f))
13931 {
13932 new_return(21);
13933 }
13934
13935
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg2,f))
13936 {
13937 new_return(22);
13938 }
13939
13940
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(zas.arg3,f))
13941 {
13942 new_return(23);
13943 }
13944
13945 2045058 uint32_t sz = 0;
13946
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 2042718 times.
2045058 if(zas.strptr)
13947 2340 sz = zas.strptr->size();
13948
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13949 {
13950 new_return(23);
13951 }
13952
2/2
✓ Branch 0 taken 2042718 times.
✓ Branch 1 taken 2340 times.
2045058 if(sz)
13953 {
13954 2340 auto& str = *zas.strptr;
13955
2/2
✓ Branch 0 taken 214720 times.
✓ Branch 1 taken 2340 times.
217060 for(size_t q = 0; q < sz; ++q)
13956 {
13957
1/2
✓ Branch 0 taken 214720 times.
✗ Branch 1 not taken.
214720 if(!p_putc(str[q],f))
13958 {
13959 new_return(24);
13960 }
13961 214720 }
13962 2340 }
13963 2045058 sz = 0;
13964
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(zas.vecptr)
13965 22 sz = zas.vecptr->size();
13966
1/2
✓ Branch 0 taken 2045058 times.
✗ Branch 1 not taken.
2045058 if(!p_iputl(sz,f))
13967 {
13968 new_return(25);
13969 }
13970
2/2
✓ Branch 0 taken 2045036 times.
✓ Branch 1 taken 22 times.
2045058 if(sz) //vector found
13971 {
13972 22 auto& vec = *zas.vecptr;
13973
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 22 times.
374 for(size_t q = 0; q < sz; ++q)
13974 {
13975
1/2
✓ Branch 0 taken 352 times.
✗ Branch 1 not taken.
352 if(!p_iputl(vec[q],f))
13976 {
13977 new_return(26);
13978 }
13979 352 }
13980 22 }
13981 }
13982 2045058 }
13983
13984 23118 new_return(0);
13985 }
13986
13987 extern SAMPLE customsfxdata[WAV_COUNT];
13988 extern uint8_t customsfxflag[WAV_COUNT>>3];
13989
13990 9 int32_t writesfx(PACKFILE *f, zquestheader *Header)
13991 {
13992 //these are here to bypass compiler warnings about unused arguments
13993 9 Header=Header;
13994
13995 9 dword section_id=ID_SFX;
13996 9 dword section_version=V_SFX;
13997 9 dword section_size=0;
13998
13999 //section id
14000
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14001 {
14002 new_return(1);
14003 }
14004
14005 //section version info
14006
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14007 {
14008 new_return(2);
14009 }
14010
14011
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14012 {
14013 new_return(3);
14014 }
14015
14016
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14017 {
14018 18 fake_pack_writing=(writecycle==0);
14019
14020 //section size
14021
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14022 {
14023 new_return(4);
14024 }
14025
14026 18 writesize=0;
14027
14028
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int32_t i=0; i<WAV_COUNT>>3; i++)
14029 {
14030
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(customsfxflag[i],f))
14031 {
14032 new_return(5);
14033 }
14034 576 }
14035
14036
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14037 {
14038
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14039 3330 continue;
14040
14041
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!pfwrite(sfx_string[i], 36, f))
14042 {
14043 new_return(5);
14044 }
14045 1260 }
14046
14047
2/2
✓ Branch 0 taken 4590 times.
✓ Branch 1 taken 18 times.
4608 for(int32_t i=1; i<WAV_COUNT; i++)
14048 {
14049
2/2
✓ Branch 0 taken 1260 times.
✓ Branch 1 taken 3330 times.
4590 if(get_bit(customsfxflag, i-1) == 0)
14050 3330 continue;
14051
14052
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].bits,f))
14053 {
14054 new_return(5);
14055 }
14056
14057
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].stereo,f))
14058 {
14059 new_return(6);
14060 }
14061
14062
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].freq,f))
14063 {
14064 new_return(7);
14065 }
14066
14067
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].priority,f))
14068 {
14069 new_return(8);
14070 }
14071
14072
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].len,f))
14073 {
14074 new_return(9);
14075 }
14076
14077
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_start,f))
14078 {
14079 new_return(10);
14080 }
14081
14082
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].loop_end,f))
14083 {
14084 new_return(11);
14085 }
14086
14087
1/2
✓ Branch 0 taken 1260 times.
✗ Branch 1 not taken.
1260 if(!p_iputl(customsfxdata[i].param,f))
14088 {
14089 new_return(12);
14090 }
14091
14092 //de-endianfy the data
14093 1260 int32_t wordstowrite = (customsfxdata[i].bits==8?1:2)*(customsfxdata[i].stereo==0?1:2)*customsfxdata[i].len/sizeof(word);
14094
14095
2/2
✓ Branch 0 taken 28596352 times.
✓ Branch 1 taken 1260 times.
28597612 for(int32_t j=0; j<wordstowrite; j++)
14096 {
14097
1/2
✓ Branch 0 taken 28596352 times.
✗ Branch 1 not taken.
28596352 if(!p_iputw(((word *)customsfxdata[i].data)[j],f))
14098 {
14099 new_return(13);
14100 }
14101 28596352 }
14102 1260 }
14103
14104
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14105 {
14106 9 section_size=writesize;
14107 9 }
14108 18 }
14109
14110
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14111 {
14112 char ebuf[80];
14113 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14114 jwin_alert("Error: writesfx()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14115 }
14116
14117 9 new_return(0);
14118 }
14119
14120 9 int32_t writeinitdata(PACKFILE *f, zquestheader *)
14121 {
14122 9 dword section_id=ID_INITDATA;
14123 9 dword section_version=V_INITDATA;
14124 9 dword section_size = 0;
14125
14126 9 zinit.last_map=Map.getCurrMap();
14127 9 zinit.last_screen=Map.getCurrScr();
14128 9 zinit.normalize();
14129
14130 //section id
14131
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14132 {
14133 new_return(1);
14134 }
14135
14136 //section version info
14137
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14138 {
14139 new_return(2);
14140 }
14141
14142
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14143 {
14144 new_return(3);
14145 }
14146
14147 //TODO
14148
14149
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14150 {
14151 18 fake_pack_writing=(writecycle==0);
14152
14153 //section size
14154
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14155 new_return(4);
14156
14157 18 writesize=0;
14158
14159
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 18 times.
594 for(int q = 0; q < MAXITEMS/8; ++q)
14160
1/2
✓ Branch 0 taken 576 times.
✗ Branch 1 not taken.
576 if(!p_putc(zinit.items[q], f))
14161 new_return(5);
14162
2/2
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 18 times.
9234 for(int q = 0; q < MAXLEVELS; ++q)
14163 {
14164
1/2
✓ Branch 0 taken 9216 times.
✗ Branch 1 not taken.
9216 if(!p_iputw(zinit.litems[q], f))
14165 new_return(6);
14166 9216 }
14167
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbvec(zinit.level_keys, f))
14168 new_return(10);
14169
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(MAX_COUNTERS,f))
14170 new_return(11);
14171
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14172
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.counter[q],f))
14173 new_return(12);
14174
2/2
✓ Branch 0 taken 1926 times.
✓ Branch 1 taken 18 times.
1944 for(int q = 0; q < MAX_COUNTERS; ++q)
14175
1/2
✓ Branch 0 taken 1926 times.
✗ Branch 1 not taken.
1926 if(!p_iputw(zinit.mcounter[q],f))
14176 new_return(13);
14177
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.bomb_ratio,f))
14178 new_return(14);
14179
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp,f))
14180 new_return(15);
14181
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hcp_per_hc,f))
14182 new_return(16);
14183
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.cont_heart,f))
14184 new_return(17);
14185
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hp_per_heart,f))
14186 new_return(18);
14187
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magic_per_block,f))
14188 new_return(19);
14189
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_damage_multiplier,f))
14190 new_return(20);
14191
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.ene_damage_multiplier,f))
14192 new_return(21);
14193
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_type,f))
14194 new_return(22);
14195
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_arg,f))
14196 new_return(23);
14197
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.dither_percent,f))
14198 new_return(24);
14199
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.def_lightrad,f))
14200 new_return(25);
14201
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.transdark_percent,f))
14202 new_return(26);
14203
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.darkcol,f))
14204 new_return(27);
14205
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_x,f))
14206 new_return(28);
14207
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_y,f))
14208 new_return(29);
14209
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_xofs,f))
14210 new_return(30);
14211
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_yofs,f))
14212 new_return(31);
14213
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_grid_color,f))
14214 new_return(32);
14215
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_1_color,f))
14216 new_return(33);
14217
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_bbox_2_color,f))
14218 new_return(34);
14219
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.ss_flags,f))
14220 new_return(35);
14221
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.flags,f))
14222 new_return(36);
14223
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_map,f))
14224 new_return(37);
14225
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.last_screen,f))
14226 new_return(38);
14227
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_x,f))
14228 new_return(39);
14229
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_y,f))
14230 new_return(40);
14231
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_more_is_offset,f))
14232 new_return(41);
14233
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.msg_speed,f))
14234 new_return(42);
14235
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.gravity,f))
14236 new_return(43);
14237
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.swimgravity,f))
14238 new_return(44);
14239
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.terminalv,f))
14240 new_return(45);
14241
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_speed,f))
14242 new_return(46);
14243
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_mult,f))
14244 new_return(47);
14245
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.hero_swim_div,f))
14246 new_return(48);
14247
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimUpStep,f))
14248 new_return(49);
14249
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimSideStep,f))
14250 new_return(50);
14251
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroSideswimDownStep,f))
14252 new_return(51);
14253
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.exitWaterJump,f))
14254 new_return(52);
14255
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.heroStep,f))
14256 new_return(53);
14257
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.heroAnimationStyle,f))
14258 new_return(54);
14259
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.jump_hero_layer_threshold,f))
14260 new_return(55);
14261
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(zinit.bunny_ltm,f))
14262 new_return(56);
14263
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.start_dmap,f))
14264 new_return(57);
14265
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(zinit.subscrSpeed,f))
14266 new_return(58);
14267
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.switchhookstyle,f))
14268 new_return(59);
14269
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putc(zinit.magicdrainrate,f))
14270 new_return(60);
14271
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputzf(zinit.shove_offset,f))
14272 new_return(61);
14273
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbitstr(zinit.gen_doscript, f))
14274 new_return(62);
14275
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_exitState, f))
14276 new_return(63);
14277
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_reloadState, f))
14278 new_return(64);
14279
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_initd, f))
14280 new_return(65);
14281
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_eventstate, f))
14282 new_return(66);
14283
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.gen_data, f))
14284 new_return(67);
14285
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_putbmap(zinit.screen_data, f))
14286 new_return(68);
14287
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickerspeed, f))
14288 new_return(69);
14289
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickercolor, f))
14290 new_return(70);
14291
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.spriteflickertransp, f))
14292 new_return(71);
14293
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputzf(zinit.air_drag, f))
14294 new_return(72);
14295
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_rate, f))
14296 new_return(73);
14297
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.light_wave_size, f))
14298 new_return(74);
14299
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.region_mapping, f))
14300 new_return(75);
14301
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 18 times.
4626 for(uint q = 0; q < NUM_BOTTLE_SLOTS; ++q)
14302
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 if (!p_putc(zinit.bottle_slot[q], f))
14303 new_return(76);
14304
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putbvec(zinit.lvlswitches, f))
14305 new_return(77);
14306
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_spawn_flicker, f))
14307 new_return(78);
14308
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_dur, f))
14309 new_return(79);
14310
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_iputw(zinit.item_timeout_flicker, f))
14311 new_return(80);
14312
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if (!p_putc(zinit.item_flicker_speed, f))
14313 new_return(81);
14314
2/2
✓ Branch 0 taken 90 times.
✓ Branch 1 taken 18 times.
108 for(int q = 0; q < SPRITE_THRESHOLD_MAX; ++q)
14315
1/2
✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
90 if (!p_iputw(zinit.sprite_z_thresholds[q], f))
14316 new_return(82);
14317
14318
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14319 {
14320 9 section_size=writesize;
14321 9 }
14322 18 }
14323
14324
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14325 {
14326 char ebuf[80];
14327 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14328 jwin_alert("Error: writeinitdata()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14329 }
14330
14331 9 new_return(0);
14332 }
14333
14334 9 int32_t writeitemdropsets(PACKFILE *f, zquestheader *Header)
14335 {
14336 //these are here to bypass compiler warnings about unused arguments
14337 9 Header=Header;
14338
14339 9 dword section_id=ID_ITEMDROPSETS;
14340 9 dword section_version=V_ITEMDROPSETS;
14341 // dword section_size=0;
14342 9 dword section_size = 0;
14343 9 word num_item_drop_sets=count_item_drop_sets();
14344
14345 //section id
14346
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14347 {
14348 new_return(1);
14349 }
14350
14351 //section version info
14352
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14353 {
14354 new_return(2);
14355 }
14356
14357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14358 {
14359 new_return(3);
14360 }
14361
14362
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14363 {
14364 18 fake_pack_writing=(writecycle==0);
14365
14366 //section size
14367
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14368 {
14369 new_return(4);
14370 }
14371
14372 18 writesize=0;
14373
14374 //finally... section data
14375
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(num_item_drop_sets,f))
14376 {
14377 new_return(5);
14378 }
14379
14380
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 18 times.
254 for(int32_t i=0; i<num_item_drop_sets; i++)
14381 {
14382
1/2
✓ Branch 0 taken 236 times.
✗ Branch 1 not taken.
236 if(!pfwrite(item_drop_sets[i].name, sizeof(item_drop_sets[i].name)-1, f))
14383 {
14384 new_return(6);
14385 }
14386
14387
2/2
✓ Branch 0 taken 2360 times.
✓ Branch 1 taken 236 times.
2596 for(int32_t j=0; j<10; ++j)
14388 {
14389
1/2
✓ Branch 0 taken 2360 times.
✗ Branch 1 not taken.
2360 if(!p_iputw(item_drop_sets[i].item[j],f))
14390 {
14391 new_return(7);
14392 }
14393 2360 }
14394
14395
2/2
✓ Branch 0 taken 2596 times.
✓ Branch 1 taken 236 times.
2832 for(int32_t j=0; j<11; ++j)
14396 {
14397
1/2
✓ Branch 0 taken 2596 times.
✗ Branch 1 not taken.
2596 if(!p_iputw(item_drop_sets[i].chance[j],f))
14398 {
14399 new_return(8);
14400 }
14401 2596 }
14402 236 }
14403
14404
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14405 {
14406 9 section_size=writesize;
14407 9 }
14408 18 }
14409
14410
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14411 {
14412 char ebuf[80];
14413 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14414 jwin_alert("Error: writeitemdropsets()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14415 }
14416
14417 9 new_return(0);
14418 }
14419
14420 9 int32_t writefavorites(PACKFILE *f, zquestheader*)
14421 {
14422 9 dword section_id=ID_FAVORITES;
14423 9 dword section_version=V_FAVORITES;
14424 9 dword section_size = 0;
14425
14426 //section id
14427
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_mputl(section_id,f))
14428 {
14429 new_return(1);
14430 }
14431
14432 //section version info
14433
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!p_iputw(section_version,f))
14434 {
14435 new_return(2);
14436 }
14437
14438
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(!write_deprecated_section_cversion(section_version,f))
14439 {
14440 new_return(3);
14441 }
14442
14443
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 18 times.
27 for(int32_t writecycle=0; writecycle<2; ++writecycle)
14444 {
14445 18 fake_pack_writing=(writecycle==0);
14446
14447 //section size
14448
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputl(section_size,f))
14449 new_return(4);
14450
14451 18 writesize=0;
14452
14453
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_ROW,f))
14454 new_return(16);
14455
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(FAVORITECOMBO_PER_PAGE,f)) // Just in case pages get resized again
14456 new_return(17);
14457
14458 18 word favcmb_cnt = 0;
14459
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 22234 times.
22238 for(int q = MAXFAVORITECOMBOS-1; q >= 0; --q)
14460
2/2
✓ Branch 0 taken 22220 times.
✓ Branch 1 taken 14 times.
22234 if(favorite_combos[q] != -1)
14461 {
14462 14 favcmb_cnt = q+1;
14463 14 break;
14464 }
14465
14466
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(favcmb_cnt,f)) // This'll probably never change, huh?
14467 new_return(5);
14468
14469
2/2
✓ Branch 0 taken 460 times.
✓ Branch 1 taken 18 times.
478 for(int i=0; i<favcmb_cnt; ++i)
14470 {
14471
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_putc(favorite_combo_modes[i], f))
14472 new_return(6);
14473
1/2
✓ Branch 0 taken 460 times.
✗ Branch 1 not taken.
460 if (!p_iputl(favorite_combos[i], f))
14474 new_return(7);
14475 460 }
14476
14477
14478 18 word max_combo_cols = MAX_COMBO_COLS;
14479
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_combo_cols,f))
14480 new_return(9);
14481
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 18 times.
90 for(int q = 0; q < max_combo_cols; ++q)
14482 {
14483
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(First[q],f))
14484 new_return(10);
14485
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_alistpos[q],f))
14486 new_return(11);
14487
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(!p_iputl(combo_pool_listpos[q],f))
14488 new_return(12);
14489 72 }
14490 18 word max_mappages = MAX_MAPPAGE_BTNS;
14491
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
18 if(!p_iputw(max_mappages,f))
14492 new_return(13);
14493
2/2
✓ Branch 0 taken 162 times.
✓ Branch 1 taken 18 times.
180 for(int q = 0; q < max_mappages; ++q)
14494 {
14495
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].map,f))
14496 new_return(14);
14497
1/2
✓ Branch 0 taken 162 times.
✗ Branch 1 not taken.
162 if(!p_iputl(map_page[q].screen,f))
14498 new_return(15);
14499 162 }
14500
14501
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 9 times.
18 if(writecycle==0)
14502 {
14503 9 section_size=writesize;
14504 9 }
14505 18 }
14506
14507
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(writesize!=int32_t(section_size) && save_warn)
14508 {
14509 char ebuf[80];
14510 sprintf(ebuf, "%d != %d", writesize, int32_t(section_size));
14511 jwin_alert("Error: writefavorites()","writesize != section_size",ebuf,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
14512 }
14513
14514 9 new_return(0);
14515 }
14516
14517 9 static int32_t _save_unencoded_quest_int(const char *filename, bool compressed, const char *afname)
14518 {
14519
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!afname) afname = filename;
14520 9 reset_combo_animations();
14521 9 reset_combo_animations2();
14522 9 strcpy(header.id_str,QH_NEWIDSTR);
14523 9 header.zelda_version = ZELDA_VERSION;
14524 9 header.internal = INTERNAL_VERSION;
14525 9 header.data_flags[ZQ_TILES] = true;
14526 9 header.data_flags[ZQ_CHEATS2] = 1;
14527 9 header.build=VERSION_BUILD;
14528
14529
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMMIDIS; i++)
14530 {
14531 2268 set_bit(midi_flags,i,int32_t(customtunes[i].data!=NULL));
14532 2268 }
14533
14534 char zinfofilename[2048];
14535 9 replace_extension(zinfofilename, afname, "zinfo", 2047);
14536
14537 9 box_start(1, "Saving Quest", get_zc_font(font_lfont), font, true);
14538 9 box_out("Saving Quest...");
14539 9 box_eol();
14540 9 box_eol();
14541
14542
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 std::string tmp_filename = util::create_temp_file_path(filename);
14543
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 PACKFILE *f = pack_fopen_password(tmp_filename.c_str(),compressed?F_WRITE_PACKED:F_WRITE, "");
14544
14545
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!f)
14546 return 1;
14547
14548
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Header...");
14549
14550
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeheader(f,&header)!=0)
14551 return 2;
14552
14553
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14554
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14555
14556
14557
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(header.external_zinfo)
14558 {
14559 PACKFILE *inf = pack_fopen_password(zinfofilename, F_WRITE, "");
14560
14561 box_out("Writing ZInfo...");
14562 if(inf)
14563 {
14564 if(writezinfo(inf,ZI)!=0)
14565 return 2;
14566
14567 pack_fclose(inf);
14568 box_out("okay.");
14569 }
14570 else box_out(" ...file failure");
14571 box_eol();
14572 }
14573 else
14574 {
14575
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing ZInfo...");
14576
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writezinfo(f,ZI)!=0)
14577 return 2;
14578
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14579
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14580 }
14581
14582
14583
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Rules...");
14584
14585
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writerules(f,&header)!=0)
14586 return 3;
14587
14588
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14589
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14590
14591
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Strings...");
14592
14593
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writestrings(f, ZELDA_VERSION, VERSION_BUILD, 0, MAXMSGS)!=0)
14594 return 4;
14595
14596
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14597
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14598
14599
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Doors...");
14600
14601
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedoorcombosets(f,&header)!=0)
14602 return 5;
14603
14604
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14605
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14606
14607
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing DMaps...");
14608
14609
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writedmaps(f,header.zelda_version,header.build,0,MAXDMAPS)!=0)
14610 return 6;
14611
14612
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14613
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14614
14615
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Data...");
14616
14617
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemisc(f,&header)!=0)
14618 return 7;
14619
14620
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14621
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14622
14623
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing &QMisc. Colors...");
14624
14625
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemisccolors(f,&header)!=0)
14626 return 8;
14627
14628
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14629
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14630
14631
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Game Icons...");
14632
14633
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writegameicons(f,&header)!=0)
14634 return 9;
14635
14636
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14637
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14638
14639
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Items...");
14640
14641
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeitems(f,&header)!=0)
14642 return 10;
14643
14644
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14645
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14646
14647
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Weapons...");
14648
14649
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeweapons(f,&header)!=0)
14650 return 11;
14651
14652
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14653
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14654
14655
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Maps...");
14656
14657
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writemaps(f,&header)!=0)
14658 return 12;
14659
14660
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14661
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14662
14663
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combos...");
14664
14665
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecombos(f,header.zelda_version,header.build,0,MAXCOMBOS)!=0)
14666 return 13;
14667
14668
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14669
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14670
14671
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Combo Aliases...");
14672
14673
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecomboaliases(f,header.zelda_version,header.build)!=0)
14674 return 14;
14675
14676
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14677
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14678
14679
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Color Data...");
14680
14681
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writecolordata(f,header.zelda_version,header.build,0,newerpdTOTAL)!=0)
14682 return 15;
14683
14684
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14685
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14686
14687
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Tiles...");
14688
14689
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writetiles(f,header.zelda_version,header.build,0,NEWMAXTILES)!=0)
14690 return 16;
14691
14692
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14693
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14694
14695
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing MIDIs...");
14696
14697
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writemidis(f)!=0)
14698 return 17;
14699
14700
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14701
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14702
14703
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Cheat Codes...");
14704
14705
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writecheats(f,&header)!=0)
14706 return 18;
14707
14708
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14709
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14710
14711
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Init. Data...");
14712
14713
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeinitdata(f,&header)!=0)
14714 return 19;
14715
14716
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14717
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14718
14719
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Guy Data...");
14720
14721
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeguys(f,&header)!=0)
14722 return 20;
14723
14724
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14725
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14726
14727
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Hero Sprite Data...");
14728
14729
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeherosprites(f,&header)!=0)
14730 return 21;
14731
14732
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14733
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14734
14735
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Custom Subscreen Data...");
14736
14737
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesubscreens(f,&header)!=0)
14738 return 22;
14739
14740
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14741
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14742
14743
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing FF Script Data...");
14744
14745
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writeffscript(f,&header)!=0)
14746 return 23;
14747
14748
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14749
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14750
14751
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing SFX Data...");
14752
14753
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writesfx(f,&header)!=0)
14754 return 24;
14755
14756
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14757
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14758
14759
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Item Drop Sets...");
14760
14761
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 if(writeitemdropsets(f, &header)!=0)
14762 return 25;
14763
14764
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14765
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14766
14767
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("Writing Favorite Combos...");
14768
14769
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 if(writefavorites(f, &header)!=0)
14770 return 26;
14771
14772
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_out("okay.");
14773
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 box_eol();
14774
14775
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 pack_fclose(f);
14776
14777
14778
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
9 if(header.use_keyfile&&header.dirty_password)
14779 {
14780 char const* kfname = filename;
14781 char keyfilename[2048]={0};
14782 zprint2("Writing key files for '%s'\n", kfname);
14783
14784 char temp_pw[QSTPWD_LEN] = {0};
14785 uint ind = 0;
14786 for(char const* ext : {"key","zpwd","zcheat"})
14787 {
14788 replace_extension(keyfilename, kfname, ext, 2047);
14789 PACKFILE *fp = pack_fopen_password(keyfilename, F_WRITE, "");
14790 char msg[80] = {0};
14791 sprintf(msg, "ZQuest Auto-Generated Quest Password Key File. DO NOT EDIT!");
14792 msg[78]=13;
14793 msg[79]=10;
14794 pfwrite(msg, 80, fp);
14795 p_iputw(header.zelda_version,fp);
14796 p_putc(header.build,fp);
14797 char const* pwd = header.password;
14798 if(ind == 2) //.zcheat, hashed pwd
14799 {
14800 char hashmap = 'Z';
14801 hashmap += 'Q';
14802 hashmap += 'U';
14803 hashmap += 'E';
14804 hashmap += 'S';
14805 hashmap += 'T';
14806 for ( int q = 0; q < QSTPWD_LEN; ++q )
14807 {
14808 temp_pw[q] = header.password[q];
14809 temp_pw[q] += hashmap;
14810 }
14811 pwd = temp_pw;
14812 }
14813 pfwrite(pwd, strlen(pwd), fp);
14814 pack_fclose(fp);
14815 ++ind;
14816 }
14817 }
14818
14819 // Move file to destination at end, to avoid issues with file being unavailable to test mode.
14820 9 std::error_code ec;
14821
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 fs::rename(tmp_filename, filename, ec);
14822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if (ec)
14823 {
14824 al_trace("Error saving: %s\n", std::strerror(ec.value()));
14825 return ec.value();
14826 }
14827
14828
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 strncpy(header.zelda_version_string, getVersionString(), sizeof(header.zelda_version_string));
14829
14830 #ifdef __EMSCRIPTEN__
14831 em_sync_fs();
14832 #endif
14833
14834 9 return 0;
14835 9 }
14836
14837 // #ifdef _WIN32
14838 // static std::time_t to_time_t(FILETIME const& ft) {
14839 // uint64_t t = (static_cast<uint64_t>(ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
14840 // t -= 116444736000000000ull;
14841 // t /= 10000000u;
14842 // return static_cast<std::time_t>(t);
14843 // }
14844 // #else
14845 // #endif
14846 template<typename TP>
14847 5 static std::time_t to_time_t(TP tp) {
14848 using namespace std::chrono;
14849 5 auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
14850 5 return system_clock::to_time_t(sctp);
14851 }
14852
14853 5 std::string get_time_last_modified_string(std::string path)
14854 {
14855
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 auto write_time = fs::last_write_time(path);
14856 // TODO: C++20 but not supported yet.
14857 // auto tt = std::chrono::clock_cast<std::chrono::system_clock>(write_time);
14858 5 std::time_t tt = to_time_t(write_time);
14859 5 std::tm *gmt = std::gmtime(&tt);
14860 5 std::stringstream buffer;
14861
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 buffer << std::put_time(gmt, "%Y-%m-%d");
14862
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 std::string formattedFileTime = buffer.str();
14863 5 return formattedFileTime;
14864
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 }
14865
14866 9 int32_t save_unencoded_quest(const char *filename, bool compressed, const char *afname)
14867 {
14868 // Always backup quest if it was last saved in a different version of the editor,
14869 // or if this a new file and is overwritting another qst file.
14870
10/16
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 6 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 5 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 if (exists(filename) && std::string(getVersionString()) != header.zelda_version_string)
14871 {
14872 5 std::string backup_name;
14873
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 std::string last_mod = get_time_last_modified_string(filename);
14874
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if (strlen(header.zelda_version_string) > 0)
14875 {
14876
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 backup_name = fmt::format("{}-v{}", last_mod, header.zelda_version_string);
14877 5 }
14878 else
14879 {
14880 backup_name = fmt::format("{}", last_mod);
14881 }
14882
7/14
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 5 times.
✗ Branch 13 not taken.
5 std::string backup_fname = fmt::format("{}-{}{}", fs::path(filename).stem().string(), backup_name, fs::path(filename).extension().string());
14883
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 fs::path backup_path = fs::path("backups") / backup_fname;
14884
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 if (!fs::exists(backup_path))
14885 {
14886
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
5 fs::create_directories(fs::path("backups"));
14887
3/6
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
5 if (fs::copy_file(filename, backup_path))
14888 {
14889
5/10
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 5 times.
5 InfoDialog("Quest Backup", fmt::format("A backup has been saved to {}", backup_path.string())).show();
14890 5 }
14891 else
14892 {
14893 InfoDialog("Quest Backup", fmt::format("Failed to save backup at {}", backup_path.string())).show();
14894 }
14895 5 }
14896 5 }
14897
14898 9 auto ret = _save_unencoded_quest_int(filename,compressed,afname);
14899 9 fake_pack_writing = false;
14900
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(ret)
14901 {
14902 box_out("-- Error saving quest file! --");
14903 box_end(true);
14904 }
14905 9 else box_end(false);
14906 9 return ret;
14907 }
14908
14909 9 int32_t save_quest(const char *filename, bool timed_save)
14910 {
14911
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 int32_t retention=timed_save?AutoSaveRetention:AutoBackupRetention;
14912
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 bool compress=!(timed_save&&UncompressedAutoSaves);
14913 char ext1[5];
14914 9 ext1[0]=0;
14915
14916
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 if(timed_save)
14917 {
14918 sprintf(ext1, "qt");
14919 }
14920 else
14921 {
14922 9 sprintf(ext1, "qb");
14923 }
14924
14925
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(retention)
14926 {
14927 char backupname[2048];
14928 char backupname2[2048];
14929 char ext[12];
14930
14931 for(int32_t i=retention-1; i>0; --i)
14932 {
14933 sprintf(ext, "%s%d", ext1, i-1);
14934 replace_extension(backupname, filepath, ext, 2047);
14935
14936 if(exists(backupname))
14937 {
14938 sprintf(ext, "%s%d", ext1, i);
14939 replace_extension(backupname2, filepath, ext, 2047);
14940
14941 if(exists(backupname2))
14942 {
14943 remove(backupname2);
14944 }
14945
14946 rename(backupname, backupname2);
14947 }
14948 }
14949
14950 //don't do this if we're not saving to the same name -DD
14951 if(!timed_save && !strcmp(filepath, filename))
14952 {
14953 sprintf(ext, "%s%d", ext1, 0);
14954 replace_extension(backupname, filepath, ext, 2047);
14955 rename(filepath, backupname);
14956 }
14957 }
14958
14959 int32_t ret;
14960 9 ret = save_unencoded_quest(filename, compress, filename);
14961
14962 9 return ret;
14963 }
14964
14965 8 void center_zq_class_dialogs()
14966 {
14967 8 jwin_center_dialog(pwd_dlg);
14968 8 }
14969
14970 void zmap::prv_secrets(bool high16only)
14971 {
14972 mapscr *s = &prvscr;
14973 mapscr *t = prvlayers;
14974 int32_t ft=0;
14975
14976 for(int32_t i=0; i<176; i++)
14977 {
14978 if(!high16only)
14979 {
14980 for(int32_t j=-1; j<6; j++)
14981 {
14982 int32_t newflag = -1;
14983
14984 for(int32_t iter=0; iter<2; ++iter)
14985 {
14986 if(!t[j].valid)
14987 continue;
14988
14989 int32_t checkflag=combobuf[t[j].data[i]].flag;
14990
14991 if(iter==1)
14992 {
14993 checkflag=t[j].sflag[i];
14994 }
14995
14996 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
14997 if (ft != -1)
14998 {
14999 if(j==-1)
15000 {
15001 s->data[i] = s->secretcombo[ft];
15002 s->cset[i] = s->secretcset[ft];
15003 newflag = s->secretflag[ft];
15004 }
15005 else
15006 {
15007 t[j].data[i] = t[j].secretcombo[ft];
15008 t[j].cset[i] = t[j].secretcset[ft];
15009 newflag = t[j].secretflag[ft];
15010 }
15011 }
15012 }
15013
15014 if(newflag >-1)
15015 {
15016 ((j==-1) ? s->sflag[i] : t[j].sflag[i]) = newflag;
15017 }
15018 }
15019 }
15020
15021 //if(true)
15022 //{
15023 int32_t newflag = -1;
15024
15025 for(int32_t iter=0; iter<2; ++iter)
15026 {
15027 int32_t checkflag=combobuf[s->data[i]].flag;
15028
15029 if(iter==1)
15030 {
15031 checkflag=s->sflag[i];
15032 }
15033
15034 if((checkflag > 15)&&(checkflag < 32))
15035 {
15036 s->data[i] = s->secretcombo[(checkflag)-16+4];
15037 s->cset[i] = s->secretcset[(checkflag)-16+4];
15038 newflag = s->secretflag[(checkflag)-16+4];
15039 // putit = true;
15040 }
15041 }
15042
15043 if(newflag >-1) s->sflag[i] = newflag;
15044
15045 for(int32_t j=0; j<6; j++)
15046 {
15047 if(!t[j].valid) continue;
15048
15049 int32_t newflag2 = -1;
15050
15051 for(int32_t iter=0; iter<2; ++iter)
15052 {
15053 int32_t checkflag=combobuf[t[j].data[i]].flag;
15054
15055 if(iter==1)
15056 {
15057 checkflag=t[j].sflag[i];
15058 }
15059
15060 if((checkflag > 15)&&(checkflag < 32))
15061 {
15062 t[j].data[i] = t[j].secretcombo[(checkflag)-16+4];
15063 t[j].cset[i] = t[j].secretcset[(checkflag)-16+4];
15064 newflag2 = t[j].secretflag[(checkflag)-16+4];
15065 }
15066 }
15067
15068 if(newflag2 >-1) t[j].sflag[i] = newflag2;
15069 }
15070 }
15071
15072 //FFCs
15073 word num_ffcs = s->numFFC();
15074 for(word i=0; i<num_ffcs; ++i)
15075 {
15076 if(!high16only)
15077 {
15078 for(int32_t iter=0; iter<1; ++iter)
15079 {
15080 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15081
15082 if(iter==1)
15083 {
15084 checkflag=s->sflag[i];
15085 }
15086
15087 ft = combo_trigger_flag_to_secret_combo_index(checkflag);
15088 if (ft != -1)
15089 {
15090 s->ffcs[i].data = s->secretcombo[ft];
15091 s->ffcs[i].cset = s->secretcset[ft];
15092 }
15093 }
15094 }
15095
15096 if(!(s->flags2&fCLEARSECRET) || high16only || s->flags4&fENEMYSCRTPERM)
15097 {
15098 for(int32_t iter=0; iter<1; ++iter)
15099 {
15100 int32_t checkflag=combobuf[s->ffcs[i].data].flag;
15101
15102 if(iter==1)
15103 {
15104 // FFCs can't have flags! Yet...
15105 }
15106
15107 if((checkflag > 15)&&(checkflag < 32))
15108 {
15109 s->ffcs[i].data = s->secretcombo[checkflag - 16 + 4];
15110 s->ffcs[i].cset = s->secretcset[checkflag-16+4];
15111 }
15112 }
15113 }
15114 }
15115 }
15116